|
-
Jan 18th, 2006, 06:39 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] undefined???
I get an error message "undefined" for the following script..
any help?
thanks
VB Code:
<html><head>
<script>
var h=0;
function yaz()
{
for(h=0;h<=6;h++)
{
var rno=(Math.floor(Math.random()*50)+1);
document.getElementById('oda').innerHTML=rno[h];
}
}
</script></head><body>
<div id="oda">......</div>
<form>
<input type=button value="print the rand nums" onClick="yaz()">
</form></body></html>
-
Jan 18th, 2006, 09:11 AM
#2
Frenzied Member
Re: undefined???
rno is not an array. Try removing the [h] in innerHTML=rno[h];
-
Jan 18th, 2006, 11:46 AM
#3
Thread Starter
Fanatic Member
Re: undefined???
still get an error saying..
"document.getElementById("...").innerHTML..." is NULL or not an object
it prints only one num...where as I need six nums..
so how shall I fix it?
thanks
Last edited by merhaba; Jan 18th, 2006 at 11:52 AM.
-
Jan 18th, 2006, 03:45 PM
#4
Frenzied Member
Re: undefined???
Not sure why you are getting the error. It ran for me in IE6.0.
It actually prints all 7 (not 6) numbers generated. The problem is that you only see the last number because:
1) you replace the innerhtml each pass through the loop, and
2) it executes too fast to see each change.
If you only want 6 numbers then remove the '=' from 'h<=6;'.
Take a look at this
Code:
<html>
<head>
<script>
var h=0;
function yaz()
{
document.getElementById('oda').innerHTML = '';
for (h=0;h<=6;h++)
{
var rno = (Math.floor(Math.random()*50)+1);
document.getElementById('oda').innerHTML += rno + '<br>';
}
}
</script>
</head>
<body>
<div id="oda">......</div>
<form>
<input type=button value="print the rand nums" onClick="yaz()">
</form>
</body>
</html>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|