Accessing Radio Buttons

Slightly more complicated than text boxes are radio buttons.
Radio buttons usually occur in groups because clicking on one is supposed to disable the others

Female Male Other

In the above example we use three radio buttons named male , female and other, and an ordinary button.

Clicking the button displays an alert box which states which radio button is currently selected.

Here is some similar code

<head><script type='text/javascript'>
function showChoice() {
if (document.forms[0].gender[0].checked)
{alert ("You are female")}
if (document.forms[0].gender[1].checked)
{alert ("You are male")}
}
</script></head>
<body>
<form>
<input type="radio" name="gender" value="Female" checked='checked' /> Female
<input type="radio" name="gender" value="Male" /> Male
<input type="button" value="Click Me" onclick="showChoice()">
</form>
</body>

Exercise
Make the code above identical to the example shown at the top of the page.