Question : Loop through radio buttons using javascript

I have a form that contains a bunch of radio buttons - that is built dynamically from my DB.

How can I read through the radio buttons named apradio to determine which one was selected?

The HTML code for the radio button is:
<input type='radio' name='apradio' id='apradio' value='1'>
<input type='radio' name='apradio' id='apradio' value='2'>
Etc.

Thanks...



Answer : Loop through radio buttons using javascript

Does this help?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
<html>
<body>

1<input type='radio' name='apradio' value='1' onclick='which("apradio")'><br>
2<input type='radio' name='apradio' value='2'
onclick='which("apradio")'><br>
3<input type='radio' name='apradio' value='3'
onclick='which("apradio")'><br>
4<input type='radio' name='apradio' value='4' onclick='which("apradio")'><br>

<script type='text/javascript'>
  function which( name ) {
    var radio = document.getElementsByName( name );
    var result  = 'None';
    for ( var i = 0; i < radio.length; i++ ) {
      if ( radio[ i ].checked ) {
        result = radio[ i ].value;
      }
    }
    alert( result );
  }
</script>

</body>
</html>
Random Solutions  
 
programming4us programming4us