radio button


<input type="radio">

Browser
Internet Explorer Firefox Opera
Type
Inline-block Empty

The INPUT element defines an input field. When you specify "radio" for the type attribute of this element, a radio button is created.


<input type="radio" name="example" value="yes">Yes

<input type="radio" name="example" value="no" checked>No


Attribute Value Explanation
type=" " radio the type of input field
name=" " field name a unique name for the field
value=" " initial value this value is submitted
checked checked that button is checked
(HTML : checked | XHTML : checked="checked")

type="radio"

Creates a radio button on the form.

name=""

The field name is used to identify the form field.

Several radio buttons can share the same field name, and only one can be selected within that.

value=""

This value is submitted to the server when selected.

checked

That button is checked in the initial state.


Example

<form method="POST" action="example.cgi">

<p>
Question 1 : Do you like baseball?
<input type="radio" name="q1" value="yes">Yes
<input type="radio" name="q1" value="no">No
</p>

<p>
Question 2 : Do you like football?
<input type="radio" name="q2" value="yes">Yes
<input type="radio" name="q2" value="no">No
</p>

</form>
Output

Question 1 : Do you like baseball? Yes No

Question 2 : Do you like football? Yes No

This form cannot submit because of a sample.


Example of having selected the "Yes"

<form method="POST" action="example.cgi">

<p>
Question 3 : Do you like ice hockey?
<input type="radio" name="q3" value="yes" checked>Yes
<input type="radio" name="q3" value="no">No
</p>

</form>
Output

Question 3 : Do you like ice hockey? Yes No

This form cannot submit because of a sample.