Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > passing variable - no answer?!

Reply
Thread Tools

passing variable - no answer?!

 
 
Geoff Cox
Guest
Posts: n/a
 
      09-29-2005
Hello,

I have written before that I can pass a variable from page 1 to page 2
if I call the variable "name".

Stephen Chalmers has written,

>'name' is effectively a reserved word as the variable window.name is
>created automatically, but is not read-only.
>Use more imaginative names for variables.


Does this explain why I can pass the variable from one page to
another?

It does seem to be much simpler that other methods, eg passing the
value with the URL etc.

Does doing this have any negative side effect?


Cheers

Geoff



 
Reply With Quote
 
 
 
 
ASM
Guest
Posts: n/a
 
      09-29-2005
Geoff Cox a écrit :

> Does this explain why I can pass the variable from one page to
> another?


nothing best than a try-demo :

file 'page1.htm' :

<html> <title>page 1</title>
<h3>page 1</h3>
<form action="page2.htm" onsubmit="window.name=this.Name.value">
Enter your name : <input type=text name="Name">
<input type=submit value=GO>
</form></html>

file 'page2.htm' :

<html> <title>page 2</title>
<body onload="document.forms[0][0].value = window.name;">
<h3>page 2</h3>
<form>
Your name is : <input type=text name="Name">
</form></body></html>

> It does seem to be much simpler that other methods, eg passing the
> value with the URL etc.


yes, if you have only one alone value to pass

> Does doing this have any negative side effect?


what negative effect ?


--
Stephane Moriaux et son [moins] vieux Mac
 
Reply With Quote
 
 
 
 
Geoff Cox
Guest
Posts: n/a
 
      09-29-2005
On Thu, 29 Sep 2005 11:36:41 +0200, ASM
<(E-Mail Removed)> wrote:

>Geoff Cox a écrit :
>
>> Does this explain why I can pass the variable from one page to
>> another?

>
>nothing best than a try-demo :
>
>file 'page1.htm' :
>
><html> <title>page 1</title>
><h3>page 1</h3>
><form action="page2.htm" onsubmit="window.name=this.Name.value">
>Enter your name : <input type=text name="Name">
><input type=submit value=GO>
></form></html>
>
>file 'page2.htm' :
>
><html> <title>page 2</title>
><body onload="document.forms[0][0].value = window.name;">
><h3>page 2</h3>
><form>
>Your name is : <input type=text name="Name">
></form></body></html>
>
>> It does seem to be much simpler that other methods, eg passing the
>> value with the URL etc.

>
>yes, if you have only one alone value to pass
>
>> Does doing this have any negative side effect?

>
>what negative effect ?


Stephane.

Thanks for trying this approach. I haven't seen any mention of this
befofe.

I was wondering whether if this uses "a sort of reserved word" whether
this can cause any problems?

Cheers

Geoff










 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      09-29-2005
Geoff Cox a écrit :
> On Thu, 29 Sep 2005 11:36:41 +0200, ASM
> <(E-Mail Removed)> wrote:
>
> Stephane.
>
> Thanks for trying this approach. I haven't seen any mention of this
> befofe.
>
> I was wondering whether if this uses "a sort of reserved word" whether
> this can cause any problems?


as said by otherwise

'name' is a reserved word for everything in javascript

in this try-demo this reserved word is used for what it was done
that's to say : to give a name to an object

because 'window' is the all first object in javascript
and
because 'window' can be omitted

if your window has a name and you do i.e. alert(name)
that would have to open an alert-box with the name of the window

so, this try-demo can become :

file 'page1.htm' :

<html> <title>page 1</title>
<script type="text/javascript">
function go(aName) { name=aName; }
</script>
<h3>page 1</h3>
<form action="page2.htm">
Enter your name :
<input type=text name="Name" onchange="go(this.value);">
<input type=submit value=GO>
</form></html>

file 'page2.htm' :

<html>
<title>page 2</title>
<body onload="document.forms[0].Name.value = name;">
<h3>page 2</h3>
<form>
Your name is :
<input type=text name="Name">
</body></form></html>


As you can see now, using IE (don't more work with FF),
what was your variable 'name'
was in fact the reserved word 'name'
and, because used alone, was : name of window



This particularism (a window records its name)
is useful with popups



--
Stephane Moriaux et son [moins] vieux Mac
 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      09-29-2005
On 29/09/2005 09:46, Geoff Cox wrote:

> [Using global 'name'] Does this explain why I can pass the variable
> from one page to another?


The property that you are using is a property of the tab or browser
instance, rather than the document, unlike most properties of the global
object.

> It does seem to be much simpler that other methods, eg passing the
> value with the URL etc.


Parsing values out of the query string (or a cookie) is hardly a
difficult task.

> Does doing this have any negative side effect?


Other than the fact that it might not work? There's no particular reason
why it should, and indeed it doesn't in Firefox.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
 
Reply With Quote
 
Geoff Cox
Guest
Posts: n/a
 
      09-29-2005
On Thu, 29 Sep 2005 16:15:55 GMT, Michael Winter
<(E-Mail Removed)> wrote:

>> Does doing this have any negative side effect?

>
>Other than the fact that it might not work? There's no particular reason
>why it should, and indeed it doesn't in Firefox.


Michael,

OK - that is a negative effect.

Thanks

Geoff







>
>Mike


 
Reply With Quote
 
Geoff Cox
Guest
Posts: n/a
 
      09-29-2005
On Thu, 29 Sep 2005 17:22:52 +0200, ASM
<(E-Mail Removed)> wrote:

>so, this try-demo can become :
>
>file 'page1.htm' :
>
><html> <title>page 1</title>
><script type="text/javascript">
>function go(aName) { name=aName; }
></script>
><h3>page 1</h3>
><form action="page2.htm">
>Enter your name :
><input type=text name="Name" onchange="go(this.value);">
><input type=submit value=GO>
></form></html>
>
>file 'page2.htm' :
>
><html>
><title>page 2</title>
><body onload="document.forms[0].Name.value = name;">
><h3>page 2</h3>
><form>
>Your name is :
><input type=text name="Name">
></body></form></html>
>
>
>As you can see now, using IE (don't more work with FF),
>what was your variable 'name'
>was in fact the reserved word 'name'
>and, because used alone, was : name of window
>
>
>
>This particularism (a window records its name)
>is useful with popups



Thanks Stephane.

Food for thought!

Cheers

Geoff
 
Reply With Quote
 
Geoff Cox
Guest
Posts: n/a
 
      09-30-2005
On Fri, 30 Sep 2005 14:18:30 GMT, "Zoe Brown"
<(E-Mail Removed)> wrote:

>> It does seem to be much simpler that other methods, eg passing the
>> value with the URL etc.

>
>no it doesn't, just pass the parameter in the query string as they were
>intended !!


Zoe,

Not sure what you mean? Could you please explain?

It is the case, as was pointed out to me, that this method does not
work with Firefox so have moved to the form/URL approach.

Cheers

Geoff

 
Reply With Quote
 
Geoff Cox
Guest
Posts: n/a
 
      10-01-2005
On Fri, 30 Sep 2005 18:58:23 GMT, "Zoe Brown"
<(E-Mail Removed)> wrote:

>
>"Geoff Cox" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed).. .
>> On Fri, 30 Sep 2005 14:18:30 GMT, "Zoe Brown"
>> <(E-Mail Removed)> wrote:
>>
>>>> It does seem to be much simpler that other methods, eg passing the
>>>> value with the URL etc.
>>>
>>>no it doesn't, just pass the parameter in the query string as they were
>>>intended !!

>>
>> Zoe,
>>
>> Not sure what you mean? Could you please explain?
>>
>> It is the case, as was pointed out to me, that this method does not
>> work with Firefox so have moved to the form/URL approach.

>
>which is what I said. Just use the form and use a post or get to get the
>data.


Zoe,

OK - with you!

Cheers

Geoff





>
>>
>> Cheers
>>
>> Geoff
>>

>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
passing copy of a pointer to a variable vs passing the copy pereges C Programming 7 06-01-2008 02:36 PM
Passing a variable value from Javascript to asp.net server variable shil ASP .Net 2 01-02-2007 09:33 PM
passing data from javascript variable to asp variable. Steve Cosh ASP General 1 11-18-2005 04:15 AM
passing javascript variable into asp variable using vbscript Jonas Daunoravicius Javascript 5 07-17-2003 04:54 AM
passing javascript variable into asp variable using vbscript Jonas Daunoravicius ASP General 5 07-17-2003 04:54 AM



Advertisments