By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,948 Members | 1,975 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,948 IT Pros & Developers. It's quick & easy.

passing variable - no answer?!

P: n/a
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

Sep 29 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/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">
</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
Sep 29 '05 #2

P: n/a
On Thu, 29 Sep 2005 11:36:41 +0200, ASM
<st*********************@wanadoo.fr.invalid> 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




Sep 29 '05 #3

P: n/a
ASM
Geoff Cox a écrit :
On Thu, 29 Sep 2005 11:36:41 +0200, ASM
<st*********************@wanadoo.fr.invalid> 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
Sep 29 '05 #4

P: n/a
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.
Sep 29 '05 #5

P: n/a
On Thu, 29 Sep 2005 16:15:55 GMT, Michael Winter
<m.******@blueyonder.co.uk> 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


Sep 29 '05 #6

P: n/a
On Thu, 29 Sep 2005 17:22:52 +0200, ASM
<st*********************@wanadoo.fr.invalid> 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
Sep 29 '05 #7

P: n/a
> 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 !!
Sep 30 '05 #8

P: n/a
On Fri, 30 Sep 2005 14:18:30 GMT, "Zoe Brown"
<zo***********@N-O-S-P-A-A-Mtesco.net> 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

Sep 30 '05 #9

P: n/a

"Geoff Cox" <ge*******@notquitecorrectfreeuk.com> wrote in message
news:ua********************************@4ax.com...
On Fri, 30 Sep 2005 14:18:30 GMT, "Zoe Brown"
<zo***********@N-O-S-P-A-A-Mtesco.net> 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.


Cheers

Geoff

Sep 30 '05 #10

P: n/a
On Fri, 30 Sep 2005 18:58:23 GMT, "Zoe Brown"
<zo***********@N-O-S-P-A-A-Mtesco.net> wrote:

"Geoff Cox" <ge*******@notquitecorrectfreeuk.com> wrote in message
news:ua********************************@4ax.com.. .
On Fri, 30 Sep 2005 14:18:30 GMT, "Zoe Brown"
<zo***********@N-O-S-P-A-A-Mtesco.net> 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


Oct 1 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.