View Full Version : auto choose...
Namuk
Mar 14th 2008, 10:16 pm
anyone know what are the function for auto choose value...
i mean, when i click the button, computer will auto to print/choose the value....
for example... i set the value that computer has to choose is A,B and C...
so, when i click the button 'choose' for example, the computer will choose anyone of A, B, C..... (computer/machine will choose randomly)...
please help me.....
thanks....
rkquest
Mar 14th 2008, 11:58 pm
This should do it...
<html>
<head>
<script type="text/javascript">
function randomChoose(element) {
var randomChoice = (Math.floor((element.length+2-2)*Math.random()) + 3) - 3;
element[randomChoice].checked = true;
}
</script>
</head>
<body>
<form name="theForm">
<input type="radio" name="choice" value="a" /> A<br/>
<input type="radio" name="choice" value="b" /> B<br/>
<input type="radio" name="choice" value="c" /> C<br/>
<input type="radio" name="choice" value="d" /> D<br/>
<input type="button" value="Random Choose" onclick="randomChoose(this.form.choice)" />
</form>
</body>
</html>
You can increase and decrease the number of choices and it should still work.
Namuk
Mar 15th 2008, 3:02 am
This should do it...
<html>
<head>
<script type="text/javascript">
function randomChoose(element) {
var randomChoice = (Math.floor((element.length+2-2)*Math.random()) + 3) - 3;
element[randomChoice].checked = true;
}
</script>
</head>
<body>
<form name="theForm">
<input type="radio" name="choice" value="a" /> A<br/>
<input type="radio" name="choice" value="b" /> B<br/>
<input type="radio" name="choice" value="c" /> C<br/>
<input type="radio" name="choice" value="d" /> D<br/>
<input type="button" value="Random Choose" onclick="randomChoose(this.form.choice)" />
</form>
</body>
</html>
You can increase and decrease the number of choices and it should still work.
thanks friend.... it work pretty..... thanks for the help.....
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.