HTML validation error: the for attribute of the label element must reference the form control

I don't know why I keep getting this error by checking my page for the http://validator.w3.org/check Error:

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 suppose I provided the id link for my label to an external form, why does it keep listening to 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> 
+8
html html5 validation asp.net-mvc-3
source share
1 answer

Do you have that:

 for="environment_form" 

and this applies to the form directly! But the for attribute should refer to an element of your form, in your case, a choice. Therefore, add the id attribute for your choice and change the "for" value, for example, for example:

 <label class="environment-label" for="environment_dropdown">Environments:</label> <select name="environment_dropdown" id="environment_dropdown" onchange="selectionChanged()"> 
+26
source share

All Articles