Randy Webb wrote:
Matt wrote:
I have no idea why id is undefined in the arrow below. Please advise.
Thanks!!
<html>
<head>
<script type="text/javascript">
var id;
function window_onload()
{
id = "8888";
alert("ID = " + id);
}
</script>
</head>
<H2>Page 2</H2>
<body onload="window_onload()">
<P>id = <script type="text/javascript">document.write(id);</script>
//<****
</body>
</html>
Because its value is not set until the onload event fires, which is
*after* you try to write it, so its not set yet. So, you get undefined
(which it is).
Yup, I tried this:
<html>
<head>
<script type="text/javascript">
var id;
function window_onload() {
//id = "8888";
alert("ID = " + id);
}
</script>
</head>
<body onload="window_onload()">
<script type="text/javascript">
var id="8888";
</script>
<form>
<P>id = <script type="text/javascript">document.write(id);</script>
</form>
</body>
</html>