HTML and CSS Reference
In-Depth Information
for instance. Radio buttons are controls that work such that one and only one
button is “on” at any time. When you click a diferent radio button, the but-
ton that was on goes “of,” and the button you just clicked becomes the “on”
button. Radio buttons are created by input elements with the type attribute set
to "radio" . A radio button is a member of a set if it has the same value for its
name attribute as other radio buttons in the same set. 5 For example:
<input type="radio" name="sex" value="male" checked/> Male
<input type="radio" name="sex" value="female"/> Female
<input type="radio" name="sex" value="other"/> Other
he value attribute supplies the value that the form returns if the corre-
sponding button is the last one clicked when the form is submitted. Note that
no default value is returned if the user ignores a group of radio buttons. Any
default value must be speciied by adding the checked attribute, as in the pre-
ceding code snippet. If more than one element in a group of radio buttons has
the checked attribute, the last one encountered becomes the default.
Enclosing an input element and its description in a label element extends
the button's sensitivity. For example:
<label><input type="radio" name="sex" value="female"/> Female </label>
Clicking the word “Female” is the same as clicking the adjacent button. his
is a friendly interface item that users appreciate. Adding a for attribute to the
label element allows the author to place the label somewhere else on the page,
such as in another table cell. he for attribute's value matches the id attribute's
value of the associated control, as in this code snippet:
<tr>
<th align="right">
<input type="radio" name="sex" id="choice-other" value="other"/>
</th>
<td align="left">
<label for="choice-other"> Other </label>
</td>
</tr>
An input element with a type attribute value of checkbox creates a single
checkbox. Unlike radio buttons, each checkbox stands alone and has a unique
5. his is an exception to the rule that names should be unique.
 
Search WWH ::




Custom Search