passing variable - no answer?!

G

Geoff Cox

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
 
A

ASM

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">
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 ?
 
G

Geoff Cox

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">
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
 
A

ASM

Geoff Cox a écrit :
On Thu, 29 Sep 2005 11:36:41 +0200, ASM

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
 
M

Michael Winter

[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
 
G

Geoff Cox

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
 
G

Geoff Cox

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
 
G

Geoff Cox

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top