隨機變數選取按鈕
<form>
</h1>你選了什麼?</h1>
<input type="radio" name="camera" value="Canon" />Canon<br>
<input type="radio" name="camera" value="Nikon" />Nikon<br>
<input type="radio" name="camera" value="Sony" />Sony<br>
</h1>你選了什麼?</h1>
<input type="radio" name="aaa" value="Olympus" />Olympus<br>
<input type="radio" name="aaa" value="Pentax" />Pentax<br>
<input type="radio" name="aaa" value="others" />others<br>
<input type="button" name="manipulator" value="將Sony設為選取" />
</form>
<script>
var form01 = document.forms[0];
var choiceSet1 = form01.camera;
var form02 = document.forms[0];
var choiceSet2 = form02.aaa;
var manipulator = form01.manipulator;
var n1=0;
var n2=0;
function setChoice1(num){choiceSet1[num].checked = true;}
function setChoice2(num){choiceSet2[num].checked = true;}
manipulator.onclick = function(){
var maxNum = 2;
var minNum = 0;
n1= Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
n2= Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum;
setChoice1(n1);
setChoice2(n2);
}
</script>