input type="radio" ElementThe input type="radio" element is an inline element declared by the XHTML 1.1 Forms Module
Elements in the Forms Module are:form | label | textarea | select | optgroup | option | button | fieldset | legend | input type="button" | input type="checkbox" | input type="file" | input type="hidden" | input type="image" | input type="password" | input type="radio" | input type="reset" | input type="submit" | input type="text"
A set of input type="radio" elements
may be used within a form
to create a set of radio buttons, where the user may select one and only one choice from
a number of options.
All radio buttons with the same name
attribute value are part of the same set.
One (and only one) of each set of radio buttons should be given the
checked attribute
to specify that this button is the one to be initially selected (or "on") within the set.
For example, the radio buttons below all have a
name attribute value of
"size" - and so are in the same set - with the middle button (indicating the size "Medium") being the option
which is "on" when the form is initially rendered:
<label for="small">Small:</label>
<input type="radio" name="size" id="small" value="1" />
<label for="medium">Medium:</label>
<input type="radio" name="size" id="medium" value="2" checked="checked" />
<label for="large">Large:</label>
<input type="radio" name="size" id="large" value="3" />
This example renders as:
The value
attribute specifies the value to be sent in the name=value pair to the processing URI
if this radio button is "on" when the form is submitted. For example, if the form containing
the example radio buttons above were submitted with the last button (for "Large") selected, the pair
submitted to the processing URI would be size=3.
Note: Although the
value
attribute is technically optional - and most browsers will make up a value to send
(usually "on") if required - you should always specify a value for your radio buttons.
This is based on a note in the W3C HTML 4.01 specifications
(*HTML 4.01 value attribute of the input element)
which says that the value attribute is optional on
input elements except when the
type attribute has the value
"radio" or "checkbox". In any case, allocating a different value to each radio button in a set provides the
mechanism for the processor to tell them apart!
A set of radio buttons, each with the same value for its name
attribute, is logically equivalent to a select list
without the multiple attribute specified.
For example, the two example divs below are logically equivalent:
<div><fieldset>
<legend>Colour:</legend>
<label for="black">Black:</label>
<input type="radio" name="colour" id="black" value="1" />
<label for="red">Red:</label>
<input type="radio" name="colour" id="red" value="2" checked="checked" />
<label for="blue">Blue:</label>
<input type="radio" name="colour" id="blue" value="3" />
</fieldset></div>
<div>
<label for="colour">Colour:</label>
<select id="colour" name="colour">
<option value="1">Black</option>
<option value="2" selected="selected">Red</option>
<option value="3">Blue</option>
</select>
</div>
These two examples render as:
As shown above, a semantically-significant method to add an overall label to a set of radio buttons, stating their
combined purpose, is to use enclose the set within a
fieldset element and label it using a
legend element. (Appearance, including removal of any border,
can be controlled using CSS.)
The label
element itself serves this purpose for the select list.
See also: input type="checkbox".
Although the type attribute is not #REQUIRED
on the input element, its default value is "text" and so must be present on input type="radio".
input type="radio" element are listed below:accesskey [ type Character ]checked [ type Boolean ]disabled [ type Boolean ]name [ type CDATA ]name attribute is not present, no data will be sent for this element - a set of radio buttons, from which one and only one may be "on", share the same name). The value sent (in a name=value pair) is that of the value attribute of this element - but data is sent only for those radio buttons which are "on" at the time of submission.Note: Although technically optional, a note in the *Forms Module DTD says that the name attribute is required on all input elements except "submit" and "reset"
tabindex [ type Number ]value [ type CDATA ]Note: Although this attribute is optional, and most browsers will make up a value to send (usually "on") if required, you should always specify a value attribute for your radio buttons (ref: *HTML 4.01 value attribute of the input element).
onblur [ type Script ]onchange [ type Script ]onfocus [ type Script ]input type="radio" element are listed below:class [ type NMTOKENS ]id [ type ID ]style [ type CDATA ], from the Style Attribute Module (deprecated)title [ type Text ]xmlns [ type URI - #FIXED 'http://www.w3.org/1999/xhtml' ]dir [ type Enumeration (ltr | rtl) ], from the Bi-directional Text Modulexml:lang [ type LanguageCode ]All attributes in the
Events Attribute Collection
are supported:onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup
input type="radio" element is:
EMPTY
See Content Model & Nesting for information about Content Model syntax and Nesting Groups.
input type="radio"This element is empty and may have no children.
input type="radio"abbr, acronym, address, cite, code, dfn, div, em, h1 - h6, kbd, p, q, samp, span, strong, varadd, dt, licaption, td, thfieldset, label, legendb, big, i, small, sub, sup, ttdel, insbdoobjectrb, rt