• Register
0 votes
495 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 5 3
6,930 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.

9 7 4
38,600 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" />

 

10 6 4
31,120 points

Related questions

0 votes
2 answers 174 views
174 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 686 views
686 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
0 votes
1 answer 1 view
1 view
Problem: I'll make a submission for a response to my question. Please, I have searched the internet but have not found any useful material, and I am now having trouble continuing my studies.
asked Mar 30 tuhin1 48.4k points
0 votes
1 answer 3 views
3 views
Problem: As I previously stated in my question, I am having difficulty learning. Could someone help assist me in completing my project?
asked Mar 30 tuhin1 48.4k points
1 vote
1 answer 4 views
4 views
Problem: I am unable to find out the solution, Please solve it : validation in javascript for registration form without alert box
asked Mar 13 MUHAMMAD MUNEEB 82.5k points
0 votes
1 answer 2 views
2 views
Problem: How to use an ID attribute to style an element in css?
asked Mar 15 ummesalma 24.5k points
1 vote
1 answer 1.8K views
1.8K views
Problem : I am very new to Angular 4. Please find below my component in Angular 4: @Component( { selector: 'input-extra-field', template: ` <div class="form-group" [formGroup]="formGroup" > <switch [attr.title]="field.etiquette" [attr.value]="field.valeur" ... .../../../forms/@angular/forms.es5.js.FormControlDirective.ngOnChanges (forms.es5.js:4617) Please guide me in fixing above Angular 4 error.
asked May 11, 2020 stewart 4k points
0 votes
1 answer 2 views
2 views
Problem; Please let me know any solution regarding this .. how do you comment out in html
asked 5 days ago Ifra 24.4k points
0 votes
1 answer 2 views
2 views
Problem: I'm working on a web form with several fields and a submit button. When the button is clicked, I have to verify that the required text boxes have been filled in and that the phone number is in the correct format.
asked Mar 31 ummesalma 24.5k points
0 votes
1 answer 2 views
2 views
i am getting the problem of which of the following classes would you use on a div element that contains a label and a control?
asked 5 days ago ashik 11.2k points