469,923 Members | 1,605 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

should this variable be available?!

Hello,

I read that moving from one page to another normally destroys a
variable. The code below allows the variable "name" to be used in a
form on the second page. How does this happen? Or am I wrong?

Thanks

Geoff

I have put the whole code of the first page below - I can then use the
value of the name variable on the second page using IE v6. Now how is
that possible?!

Geoff

<HEAD>

<SCRIPT>

function prompter(button)

{

name=prompt('What\'s your name?',"Please enter your first and
last name here, eg Jane Green");

alert("Welcome "+name + " Now read how to answer the
questions and then move to the questions");

document.getElementById('move').innerHTML =
"<button ID='move' onclick='movetoquestions()'>Move to
questions</button>";

if (button.parentNode && button.parentNode.removeChild)
{
button.parentNode.removeChild(button);
}

}

function movetoquestions()

{
window.location.href="second_page.htm";
}

</SCRIPT>

</head>

<body>

<h2 align="center">Tests</h2>

<pre>

</pre>

<p align="center"><input type="button" value="Please give us your
name" onclick="prompter(this)"></p>

<h3 align="center">How to answer a typical question</h3>

etc etc

<SPAN ID="move"></SPAN>

</body>
</html>
Sep 28 '05 #1
2 1213

Geoff Cox wrote:
Hello,

I read that moving from one page to another normally destroys a
variable. The code below allows the variable "name" to be used in a
form on the second page. How does this happen? Or am I wrong?

Thanks

Geoff

I have put the whole code of the first page below - I can then use the
value of the name variable on the second page using IE v6. Now how is
that possible?!

Geoff

<HEAD>

<SCRIPT>

function prompter(button)

{

name=prompt('What\'s your name?',"Please enter your first and
last name here, eg Jane Green");

alert("Welcome "+name + " Now read how to answer the
questions and then move to the questions");

document.getElementById('move').innerHTML =
"<button ID='move' onclick='movetoquestions()'>Move to
questions</button>";

if (button.parentNode && button.parentNode.removeChild)
{
button.parentNode.removeChild(button);
}

}

function movetoquestions()

{
window.location.href="second_page.htm";
}

</SCRIPT>

</head>

<body>

<h2 align="center">Tests</h2>

<pre>

</pre>

<p align="center"><input type="button" value="Please give us your
name" onclick="prompter(this)"></p>

<h3 align="center">How to answer a typical question</h3>

etc etc

<SPAN ID="move"></SPAN>

</body>
</html>


Someone already answered this question in your last post:

Stephen Chalmers wrote:
'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.

Sep 28 '05 #2
On 28 Sep 2005 01:27:40 -0700, "web.dev" <we********@gmail.com> wrote:

Someone already answered this question in your last post:

Stephen Chalmers wrote:
'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.


web.dev

Thanks for above - oddly enough I cannot see that response in Agent
but can when I do a Google search.

Are you saying that the fact that window.name exists is the explantion
for why the name values are available in the second page?

Cheers

Geoff

Sep 28 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by SamMan | last post: by
1 post views Thread by Gnarlodious | last post: by
40 posts views Thread by Steve Juranich | last post: by
2 posts views Thread by R.G. Vervoort | last post: by
134 posts views Thread by James A. Donald | last post: by
1 post views Thread by TSW | last post: by
8 posts views Thread by vvenk | last post: by
4 posts views Thread by comp.lang.php | last post: by
pbmods
1 post views Thread by pbmods | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.