I have a form that has 5 text boxes that each need to be filled with 4 random numbers when one button is pressed to generate them.
I don't know Javascript that well so I researched on the internet and found some code to generate random numbers. The code looks like it should work (from my limited knowledge). It returns an error message that says runtime error on the line that says "document.getElementById('ranlist1').innerHTML=rannum".
Here is the code:
I just realized that rannum will run once and return the same value to all of the fields the way I have it now. However I need the values in all of the fields to be randomly generated.
Does anyone know a better way to do this?
I don't know Javascript that well so I researched on the internet and found some code to generate random numbers. The code looks like it should work (from my limited knowledge). It returns an error message that says runtime error on the line that says "document.getElementById('ranlist1').innerHTML=rannum".
Here is the code:
Code:
<script type="text/javascript">
function genNumbers() {
var i, rannum;
for(i = 0; i < 100; i++) {
rannum = Math.random()*4;
rannum = Math.round(rannum);
document.getElementById('ranlist1').innerHTML=rannum
document.getElementById('ranlist2').innerHTML=rannum
document.getElementById('ranlist3').innerHTML=rannum
document.getElementById('ranlist4').innerHTML=rannum
document.getElementById('ranlist5').innerHTML=rannum
}
}
</script>
<input type="text" name="ranlist1" size="5" value=""> -
<input type="text" name="ranlist2" size="5" value=""> -
<input type="text" name="ranlist3" size="5" value=""> -
<input type="text" name="ranlist4" size="5" value=""> -
<input type="text" name="ranlist5" size="5" value="">
<input type="button" value="Generate Code" id="Generate" onclick="genNumbers()";>
I just realized that rannum will run once and return the same value to all of the fields the way I have it now. However I need the values in all of the fields to be randomly generated.
Does anyone know a better way to do this?