Thursday, March 12, 2009

Radio Object Javascript

This example loops through a group of radio buttons all sharing the same
name, and returns the index number of the one that's checked:



<form name="test">

<input type="radio" name="myradio" />

<input type="radio" name="myradio" checked />


<input type="radio" name="myradio" />

</form>



<script type="text/javascript">

//a variable that will hold the index number of the selected radio button

for (i=0;i<document.test.myradio.length;i++){


if (document.test.myradio[i].checked==true)

theone=i

}

</script>

No comments:

Post a Comment