Take a moment to experiment with this form and observe its behavior. When you are done, push the "view source" button to see the underlying HTML code.
As you study this source code, you will see that the radio buttons have identical names but different values.
Radioobjects, as object-properties of the form. The name of a radio button array is the same as the group name specified in the radio buttons' HTML tags.
If this object-property hierarchy of radio buttons is a little confusing, the following summary may clear things up:
document . form_name
document . form_name . radio_group_name
(Note that the first radio button in the form is index with 0, not 1.)
document . form_name . radio_group_name [radio_index]
Radioobjects contain many useful properties which can be read or assigned. These properties are given in the table below:
||indicates whether the radio button is presently checked||yes|
indicates whether the radio button is checked by default|
(i.e., checked when the form is first loaded or when the form is reset)
||the form containing the radio button||no|
||indicates the radio button name (i.e., group name)||yes|
||indicates the radio button value||yes|
The most useful property of a radio button object is
checked. You can read this property to determine if the radio button is "on," or you can assign a new value to it in order to toggle its value. Note that whenever a new value is assigned to a
checked property, the other radio buttons in the same group automatically become unchecked.
Remember the example form I showed you earlier, regarding the first president of the United States? It might be a good idea to add a "check answer" button, so that the user can find out if he or she gave the right answer. In this example, we'll use the
onClick event handler to tie the button to a function called
check_answer, which checks the user's answer and tells him or her if the answer is correct.
Well, here it is. I suppose I could explain it in detail, but I'll bet you'll understand what's going on if you just view the source.
A discussion on how to determine which radio button is selected can be found in the companion article, Function
get_radio_value. You can also look up the
28 Jan. 1997