Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what the meaning of FOR in a label tag?

In HTML, What's the purpose of the attribute for in the label tag.

<label for = "Name">Name: </label>
<% = Html.TextBox("Name")%>

In the above sample, why the label tag has a for = "Name" attribute? To mark their association??? If I don't put for what gonna happen?

Thanks for helping

like image 854
Richard77 Avatar asked May 12 '10 13:05

Richard77


2 Answers

The for attribute specifies which form element the label is bound to.

The label element allows the user to give focus to a form element by clicking on an associate label. If you do not use the for attribute, this association will not be made.

like image 190
Daniel Vassallo Avatar answered Oct 06 '22 01:10

Daniel Vassallo


If the user clicks on the label, and the for attribute matches that id of the respective control, it will toggle the control.

like image 38
Gabe Avatar answered Oct 06 '22 00:10

Gabe