HTML and CSS Reference
In-Depth Information
9.5.3. Radio Buttons
Radio button form controls are similar in behavior to checkboxes, except
by setting the
type
attribute of the
<input>
tag to
radio
. As with check-
box controls, radio buttons each require a
name
and
value
attribute. Ra-
dio buttons with the same name are members of a group. One of them
may be checked by including the
checked
attribute with that element. If
you don't check one in the group, the browser does it automatically for
you by checking the first element in the group.
[*]
Some of us are old enough, while not yet senile, to recall when automobile radios had mechanical
push buttons for selecting a station. Pushing in one button popped out the previously depressed one,
implementing a mechanical one-of-many choice mechanism.
You should give each radio button element a different value so that the
forms-processing server can sort them out after form submission.
Here's the previous example reworked in HTML so that you get to
choose only one animal as a favorite pet (see
Figure 9-4
):
Figure 9-4. Radio buttons allow only one selection per
group