floyd
floyd

Reputation: 131

The for attribute of the label element must refer to a form control

I keep getting the above error on two of my lines of label code. I haven't been able to come up with a valid solution. Any takers would be of great help.

<input type="radio" name="payment_method" value="Bill Me">
<label div id="payment1" for="payment_method">Bill Me</label>

and

<input type="radio" name="payment_method" value="Bill Me">
<label div id="payment2" for="payment_method">Credit Card</label>

Upvotes: 0

Views: 71

Answers (1)

Deviant
Deviant

Reputation: 325

The for attribute should correspond with an ID of a form control, not a name.

Give the input's a unique ID and use it as the value on each label's for, example:

<input name="payment_method" value="Bill Me" id="payment_method_bill">
<label id="payment1" for="payment_method_bill">Bill Me</label>

FYI: You have div before each label's ID, which is invalid and should be removed.

Upvotes: 4

Related Questions