Determining the Value of the Selected Radio Button : RadioButton Radio « Form Control « JavaScript DHTML






Determining the Value of the Selected Radio Button

  

<html>
<head>
<script language = "JavaScript">
     function getRadioValue(radioObject) {
          var value = null
          for (var i=0; i<radioObject.length; i++) {
               if (radioObject[i].checked) {
                    value = radioObject[i].value;
                    break ;
               }
          }
          return value
     }
</script>
</head>
<body>
    <form name="form1">
    <p><input type=radio name="songs" value="A">A</p>
    <p><input type=radio name="songs" value="B">B</p>
    <p><input type=radio name="songs" value="C">C</p>
    <input type=button value="Show Selected" onClick="alert(getRadioValue(this.form.songs))">
    </form>
</body>
</html>


           
         
    
  








Related examples in the same category

1.'defaultChecked' Example
2.Radio Button status Example
3.Check a Radio Button
4.Radio buttons in a form
5.Using the onPropertyChange Property
6.Radio action
7.Methods and Properties of the Radio Object
8.Scripting a Group of Radio Objects
9.Finding the Selected Button in a Radio Group
10.An onClick event Handler for Radio Buttons
11.Get the radio button selection
12.Get the select radio button and its value
13.Cycle the selected radio buttons