Radio

The radio button form element. Radio buttons given the same name are considered a set and are stored in an array with the set's name. A visitor can select only one radio button of the set at any given time. If a web page has five radio buttons named favorite_color, the second radio button in the set is referred to as:

window.document.the_form.favorite_color[1]

Properties

checked

FF, IE 3

true if a visitor has selected the radio button and false otherwise. Setting the property to true causes the radio button to act as if a visitor selected the button.

Example:

if (window.document.the_form.favorite_color[3].checked == true)
{
    alert("I like that color too!");
}

This if-then statement calls an alert box if a visitor selects the fourth radio button named ...

Get The Book of JavaScript, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.