gibby
09-22-2005, 12:44 AM
Hello,
Say I've got a test page that I open with the following URL:
http://localhost/test.html?name=Clark
And on the page I've got this javascript code:
<!DOCTYPE HTML "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
function sayhello(name)
{
document.write('hello ' + name + '!');
return;
}
</script>
</head>
<body>
<script language="javascript">
sayhello(name);
</script>
</body>
</html>
But when I run this page with the URL above, I get
hello !
That is, the value of name (Clark) does not show up.
I thought that in Javascript, referencing variables was as simple as using their names, so if you had a variable with a value in the URL, you could use it in your javascript code just as you would if you declared it locally. Is this wrong? Is there a different way of doing it?
You can see this page by type the following URL in the address bar:
http://www.shahspace.com/test.html?name=[yourname]
Thanks for your help.
Say I've got a test page that I open with the following URL:
http://localhost/test.html?name=Clark
And on the page I've got this javascript code:
<!DOCTYPE HTML "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
function sayhello(name)
{
document.write('hello ' + name + '!');
return;
}
</script>
</head>
<body>
<script language="javascript">
sayhello(name);
</script>
</body>
</html>
But when I run this page with the URL above, I get
hello !
That is, the value of name (Clark) does not show up.
I thought that in Javascript, referencing variables was as simple as using their names, so if you had a variable with a value in the URL, you could use it in your javascript code just as you would if you declared it locally. Is this wrong? Is there a different way of doing it?
You can see this page by type the following URL in the address bar:
http://www.shahspace.com/test.html?name=[yourname]
Thanks for your help.