• Register
0 votes
799 views

Problem :

Facing following strange error
the value of the for attribute of the label element must be the id of a non-hidden form control.
6.9k points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

The label for attribute should have the input id value as shown below

<label for="foo">Foo:</label>
<input id="foo">

Now to omit the for and id attributes completely, please put input inside label as shown below

<label>
    Foo: <input name="foo">
</label>

Also please note input cannot be hidden like <input type="hidden"> but  it can be styled as hidden <input style="display:none">

If you follow above approach then your issue will be resolved.

38.6k points
0 votes

Solution:

The label for attribute must contain the input id value

<label for="foo">Foo:</label>
<input id="foo">

To omit the for and id attributes all-together, put input inside label

<label>
    Foo: <input name="foo">
</label>

Also note, that input cannot be hidden <input type="hidden">, however it can be styled as hidden <input style="display:none">

If you use the for attribute in a label element it has to match the id of an input element in your form

<label for="field-id" style="line-height:24px;">Your Name</label><br>&nbsp;&nbsp;
<input type="text" id="field-id">

The for attribute of a <label> must refer to the id attribute of a form input.

Use:

<label for="email-field">Email</label>
<input name="email" id="email-field" type="text" />

instead of:

<label for="email-field">Email</label>
<input name="email" id="email" type="text" />

 

31.7k points

Related questions

0 votes
1 answer 8 views
8 views
Problem: Please, I need help to solve this problem : The value of the for attribute of the label element must be the id of a non-hidden form control.
asked Jun 10 Irenka Kiri 85.5k points
0 votes
2 answers 338 views
338 views
Problem : I want to know why I keep facing below error while I try to check my page on http://validator.w3.org/check The error is as below : Line 300, Column 90: The for attribute of the label element must refer to a form control. <label for="myname" style ... ;&nbsp;  <input class="css_form_namefield TooltipIstok " type="text" name="myname" value="" style="width: 600px;" maxlength="60" > </div>
asked Jan 3, 2020 alecxe 7.5k points
0 votes
1 answer 14 views
14 views
Problem: So, what precisely is the problem here : An invalid form control with name='' is not focusable?
asked Jun 25 Nahil 128k points
0 votes
1 answer 8 views
8 views
Problem: Can someone put light on this area > When validating data entered into the text boxes of a form, it is not common to check whether
asked Apr 23 ummeshani 10.8k points
0 votes
1 answer 18 views
18 views
Problem: Codeigniter form validation error message not showing
asked Jun 26 Chi Omega 168k points
0 votes
1 answer 19 views
19 views
Problem: Has anyone had this complication before? >Student registration form in html with javascript validation
asked May 7 Chi Omega 168k points
1 vote
1 answer 26 views
26 views
Problem: Need help for this problem: Registration form with validation in c# windows application.
asked Apr 25 PkGuy 25.9k points
1 vote
2 answers 28 views
28 views
Problem: Can any one figure out this problem for me? Form validation in javascript with error messages.
asked Apr 18 PkGuy 25.9k points
0 votes
1 answer 17 views
17 views
Problem : How do I solve it: Error: start tag body seen but an element of the same type was already open?
asked Jun 15 Siam55 110k points
0 votes
1 answer 849 views
849 views
Problem : I was hoping that someone may know how to resolve the below HTML5 validation error. When I try to validate my page it gives me a below error : Error Line 90, Column 63: An body start tag seen but an element of the same type was already open. <body class=" ... only find the one <body> (the one referenced by above error) and one </body>. Can anyone please tell me how to fix above error?
asked Jan 25, 2020 jwilliam 3.9k points