views:

197

answers:

5

Just ran across a "for" parameter in an HTML label tag:

<LABEL for="required-firstname">First Name</label>
            <small>*</small>
            <input name="required-firstname" type="text" tabindex="2" id="required-firstname" size="24" maxlength="40">

I'm converting this form to a PHP processed script, can I get rid of the for= parameters? (And out of curiosity, what's does it do?)

+1  A: 

It ties the label to a form element id. Some form elements, like checkboxes, can be activated by clicking on their label.

VirtuosiMedia
+14  A: 

From w3schools.org:

The tag defines a label for an input element.

The label element does not render as anything special for the user. However, it provides a usability improvement for mouse users, because if the user clicks on the text within the label element, it toggles the control.

The for attribute of the tag should be equal to the id attribute of the related element to bind them together.

HTH!

Jonas
A: 

In some browsers when you click on a text in a for tag, you'll check the box it's associated with (i.e. the for = id) or put the focus on that box. It's an ADA thing

Peter Turner
+5  A: 

The HTML label tag defines a label for a form element. They're usually used with checkboxes and radio buttons, and when the user clicks on the label it toggles the button. With a text input (and you'll have to check this to be sure) I think it only gives focus to the input when the user clicks the label.

Bill the Lizard
+3  A: 

It specifies to which element that label is bound to. In your sample code the label is there for the required-firstname input field. If the user clicks on that label, the focus will go to the bound input field. It's a usability improvement and I think you'd be better off leaving it as is. It's a good practice.

Pawel Krakowiak