Definition and usage
The for Attribute specifies the form element to which the label is bound.
Implicit and explicit connections
One of the following methods is usually used to associate the Form Control: the form control is used as the content of the tag, which is an implicit form, you can also name a target form id for the for Attribute under the <label> label. This is an explicit form.
For example, in XHTML:
Explicit contact:
[Html]
<Label for = "SSN"> Social Security Number: </label>
<Input type = "text" name = "SocSecNum" id = "SSn"/>
<Label for = "SSN"> Social Security Number: </label>
<Input type = "text" name = "SocSecNum" id = "SSn"/>
Implicit contact:
[Html]
<Label> Date of Birth: <input type = "text" name = "DofB"/> </label>
<Label> Date of Birth: <input type = "text" name = "DofB"/> </label>
The first tag is to explicitly associate the text "Social Security Number:" With the form's Social Security Number input control ("SocSecNum, the value of its for attribute is the same as the control id, which is SSN. The second tag ("Date of Birth:") does not require the for attribute, and its related controls do not require the id attribute, they are implicitly connected by placing the <input> label in the <label> label.
Instance
A simple HTML form with two input fields and related tags:
[Html]
<Form>
<Label for = "male"> Male </label>
<Input type = "radio" name = "sex" id = "male"/>
<Br/>
<Label for = "female"> Female </label>
<Input type = "radio" name = "sex" id = "female"/>
</Form>
<Form>
<Label for = "male"> Male </label>
<Input type = "radio" name = "sex" id = "male"/>
<Br/>
<Label for = "female"> Female </label>
<Input type = "radio" name = "sex" id = "female"/>
</Form>