should this variable be available?!

G

Geoff Cox

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>
 
W

web.dev

Geoff said:
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.
 
G

Geoff Cox

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
 

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

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,270
Latest member
TopCryptoTwitterChannels_

Latest Threads

Top