label for a form field


Internet Explorer Firefox Opera7

The LABEL element assign a label to a form field (item).

<label for="item1">Name : </label>
<input type="text" name="name" size="30" id="item1">

Attribute Value Explanation
for=" " ID value matches field ID value

Example that doesn't use the LABEL element

Even if the label text is clicked, the item cannot be selected.

Yes    No    Both

Example that uses the LABEL element

The item can be selected by clicking the label text.


Code example :
<input type="radio" name="example" value="Yes" id="yes"> <label for="yes">Yes</label>

The value of the for attribute is matched to the value of the id attribute.


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

<p><label for="name_f">Name :</label> <input type="text" name="name" size="25" id="name_f"></p>

Q1 : 
<input type="radio" name="q1" value="Yes" id="q1_y"> <label for="q1_y">Yes</label>
<input type="radio" name="q1" value="No" id="q1_n"> <label for="q1_n">No</label>
<input type="radio" name="q1" value="Both" id="q1_b"> <label for="q1_b">Both</label>

<label for="cmt">Comments :</label>
<textarea cols="30" rows="5" name="comment" id="cmt"></textarea>


Q1 :

This form cannot submit because of a sample.