Here's what I'm trying to do:
I have a string with 30 numbers in it. I want to generate a random
number between 0 an 30, go to that position in the string and get that
number. Here is the code you can run it and see it doesn't work. I'm
new at this (only about a week) but I thought this should work. Please
help.
It's probably something simple, but I don't see it.
<html>
<SCRIPT LANGUAGE="JavaScript1.3">
var nRandom = 0;
var nIndex = 0;
var string_of_Numbers = "849029184628003328749103294901"
/* *********************************** */
function buttonCheck()
/* *********************************** */
{
if (document.carForm.spinButton.value == "Start")
{
document.carForm.spinButton.value = "Stop";
}
else
{
document.carForm.spinButton.value ="Start";
nRandom = Math.round(Math.random() * 30 + 1);
nIndex = string_of_Numbers.indexOf(nRandom);
document.carForm.slot1.value = "Random number generated "+nRandom;
document.carForm.slot2.value = string_of_Numbers;
document.carForm.slot3.value = "Value located at that position
"+nIndex;
}
}
</SCRIPT>
<body>
<FORM NAME="carForm">
<p>
<INPUT TYPE=button VALUE=Start NAME="spinButton"
onClick=buttonCheck()>
<p>
<INPUT TYPE=text name="slot1" value="" size=50>
<p>
<INPUT TYPE=text name="slot2" value="" size=40>
<p>
<INPUT TYPE=text name="slot3" value="" size=50>
</form>
</body>
</html>