I don't know why I keep getting this error while checking my page at http://validator.w3.org/check The error was:
Line 46, Column 68: The for attribute of the label element must refer to a form control.
<label class="environment-label" for="environment_form">Environments:</label>
I believe I provided an id reference for my label
to the outer form, why it keep bugging me about this error?
<div>
<form id="environment_form" method="post">
<div class="styled-select">
<label class="environment-label" for="environment_form">Environments:</label>
<select name="environment_dropdown" onchange="selectionChanged()">
<option @(ViewData["selection"] == null || string.IsNullOrEmpty(ViewData["selection"].ToString()) ? "selected" : "")>select one</option>
@foreach (string name in Model) {
<option @(ViewData["selection"] != null && ViewData["selection"].Equals(name) ? "selected" : "")>
@name
</option>
}
</select>
</div>
</form>
</div>
An HTML form is a section of a document which contains controls such as text fields, password fields, checkboxes, radio buttons, submit button, menus etc. An HTML form facilitates the user to enter data that is to be sent to the server for processing such as name, email address, password, phone number, etc. .
The for attribute associates a label with another control explicitly: the value of the for attribute must be the same as the value of the id attribute of the associated control element. More than one LABEL may be associated with the same control by creating multiple references via the for attribute.
form: The form attribute is used to specify one or more forms to which the <input> element belongs to. max : The max attribute is used to specify the maximum value for an < input > element. required: The required attribute specifies that an input field must be filled out before submitting the form.
When specified on HTML elements, the id attribute value must be unique amongst all the IDs in the element's tree and must contain at least one character.
you have this :
for="environment_form"
and it refers to the form directly ! But the "for" attribute should refer to an element of your form, in your case to the select. So add an "id" attribute to your select and change the "for", like this fo example :
<label class="environment-label" for="environment_dropdown">Environments:</label>
<select name="environment_dropdown" id="environment_dropdown" onchange="selectionChanged()">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With