Name: <% ...">

What is the value of FOR in a tag tag?

In HTML, what is the purpose of the attribute for in the label tag.

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

In the above example, why does the tag label have the for = "Name" attribute? To mark their connection ??? If I don’t stand for what will happen?

thanks for the help

+4
source share
4 answers

The for attribute indicates which form element is attached to the label.

The label element allows the user to set focus on the form element by clicking on the associated label. If you do not use the for attribute, this association will fail.

+8
source

If you click on a label, you can, for example, check or uncheck the checkbox / radio button . The for attribute indicates which flag the label belongs to.

A complete example is available at http://www.w3schools.com/tags/tag_label.asp .

+3
source

If the user clicks on the label , and the for attribute matches that id corresponding control, he will switch the control.

+3
source

You can accomplish the same thing by including a form element in an “associated” label element. This is nice when you cannot or do not want to give identifiers to your elements.

 <label> My Label <input type="checkbox" /> </label> 
+2
source

Source: https://habr.com/ru/post/1309564/


All Articles