Get the radio button selection : RadioButton Radio « Form Control « JavaScript DHTML






Get the radio button selection

  


<html>
<head>
<title>Radio</title>

<script language="javascript">
<!--

function RadioCheck() {

var fruit = new Array('Apples', 'Oranges', 'Bananas', 'Kiwis', 'Saskatoons', 'Grapes');
var selection = document.quiz.colour;

for (i=0; i<selection.length; i++)

  if (selection[i].checked == true)
  alert(fruit[i] + ' are ' + selection[i].value + '.')

}

//-->
</script>



</head>
<body>

<form name="quiz">

  <input type="radio" name="colour" value="red">red<br>

  <input type="radio" name="colour" value="orange">orange<br>
  <input type="radio" name="colour" value="yellow">yellow<br>
  <input type="radio" name="colour" value="green">green<br>
  <input type="radio" name="colour" value="blue">blue<br>
  <input type="radio" name="colour" value="purple">purple<br>

<br>


<input type="submit" value="Check Answer" onClick="RadioCheck()">

</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.Determining the Value of the Selected Radio Button
9.Scripting a Group of Radio Objects
10.Finding the Selected Button in a Radio Group
11.An onClick event Handler for Radio Buttons
12.Get the select radio button and its value
13.Cycle the selected radio buttons