103Chapter 9Forms and Form ElementsListing 9-2:The Checkbox Object s (Web site templates)
103Chapter 9Forms and Form ElementsListing 9-2:The Checkbox Object s checked Property
Checkboxes are generally used as preferences setters, rather than as action inducers. While acheckbox object has an onclickevent handler, a click of a checkbox should never do any- thing drastic, such as navigate to another page. The Radio ObjectSetting up a group of radio objects for scripting requires a bit more work. To let the browsermanage the highlighting and unhighlighting of a related group of buttons, you must assign thesame name to each of the buttons in the group. You can have multiple groups within a form, but each member of the same group must share the same name. Assigning the same name to a form element forces the browser to manage the elements differ- ently than if they each had a unique name. Instead, the browser maintains an array list ofobjects with the same name. The name assigned to the group becomes the name of the array. Some properties apply to the group as a whole; other properties apply to individual buttonswithin the group and must be addressed via array index references. For example, you can findout how many buttons are in a group by reading the lengthproperty of the group: document.forms[0].groupName.lengthIf you want to find out if a particular button is currently highlighted via the same checkedproperty used for the checkbox you must access the button element individually: document.forms[0].groupName[0].checkedListing 9-3 demonstrates several aspects of the radio button object, including how to lookthrough a group of buttons to find out which one is checked and how to use the valueattribute and corresponding property for meaningful work. The page includes three radio buttons and a plain button. Each radio button s valueattribute contains the full name of one of the Three Stooges. When the user clicks the button,