I am trying to W3C validate the following code in my HTML5 file, but its giving me an error message: "Line 148, Column 68: The for attribute of the label element must refer to a form control." <tr> <td><label for="Contact_Me_By" id="Contact_Me_By">Please contact me by: *</label></td> <td><input type="checkbox" name="Contact_Me_By[]" value="Email" > Email<br /> <input type="checkbox" name="Contact_Me_By[]" value="Phone" > Phone </td> </tr> Code (markup): What am I doing wrong?
You're supposed to put the id in the input, not the label. For future reference, whenever I get specific errors I Google them. Pasting "The for attribute of the label element must refer to a form control." into Google brought up a StackOverflow link as the first result, and there's your answer.
My form is now W3C validated: <tr> <td><label for="Contact_Me_By">Please contact me by: *<br><small>(check all that apply)</small></label></td> <td> <input type="checkbox" name="Contact_Me_By[]" id="Contact_Me_By" value="Email">Email<br> <input type="checkbox" name="Contact_Me_By[]" value="Phone" > Phone<br></td> </tr> Code (markup):