Checking a Radio Button Group : Radio Button « Form « JavaScript Tutorial






<html>
<head>
<title>Checking a Radio Button Group</title>

<script language="javascript" type="text/javascript">
<!--//

function evalGroup()
{
     var group = document.radioForm.myRadio;
     for (var i=0; i<group.length; i++) {
       if (group[i].checked)
          break;
     }
     if (i==group.length)
        return alert("No radio button is checked");
     alert("Radio Button " + (i+1) + " is checked.");
}

//-->
</script>

</head>
<body>

<h1>Checking a Radio Button Group</h1>

<form name="radioForm">
  Radio Button 1: <input type="radio" name="myRadio" /><br />
  Radio Button 2: <input type="radio" name="myRadio" /><br />
  Radio Button 3: <input type="radio" name="myRadio" /><br />
  Radio Button 4: <input type="radio" name="myRadio" /><br /><br />
  <input type="button" value="Eval Group" onclick="evalGroup()" />
</form>

</body>
</html>








10.11.Radio Button
10.11.1.Radio
10.11.2.Radio.blur()
10.11.3.Radio.checked
10.11.4.Radio.click()
10.11.5.Radio.defaultChecked
10.11.6.Radio.focus()
10.11.7.Radio.form
10.11.8.Radio.handleEvent()
10.11.9.Radio.name
10.11.10.Radio.onBlur
10.11.11.Radio.onClick
10.11.12.Radio.onFocus()
10.11.13.Radio.type
10.11.14.Radio.value
10.11.15.Checking a Radio Button Group
10.11.16.With with RADIO and CheckBox
10.11.17.Cycle the selected radio buttons
10.11.18.An onclick Event Handler for Radio Buttons