• Register
0 votes
82 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

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.

36.1k 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" />

 

17.7k points

Related questions

0 votes
2 answers 33 views
33 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 alecxe 7.5k points
0 votes
1 answer 206 views
206 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 jwilliam 3.9k points
1 vote
1 answer 38 views
38 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 stewart 4k points
0 votes
1 answer 30 views
30 views
Problem : I am facing below error if I try to export datagrid to the excel. &ldquo;Control 'gridview1' of type 'gridview' must be placed inside a form tag with runat=server.&rdquo; Please find below my code : <form runat="server" id="form1"> <div runat="server" id=" ... TextBox> </form> My GridView is within the from tag with the runat="server", but still I am facing above error. How to fix this?
asked Feb 17 mphil 2.3k points
0 votes
1 answer 1.5K views
1.5K views
Problem : I am facing following error from the Angular 2 core.umd.js:5995 EXCEPTION: Uncaught (in promise): Error: Error in app/model_exposure_currencies/model_exposure_currencies.component.html:57:18 caused by: If ngModel is used within a form tag, either the name attribute must be set or the form ... 0-9]+)?" required> </div> </td> Below is my form tag: <form #f="ngForm" (ngSubmit)="onSubmit()">
asked Dec 3, 2019 alecxe 7.5k points