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

should this variable be available?!

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a

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

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