Jump to content
Larry Ullman's Book Forums

Ch2 - P39, A Question On The <Label For="Gender"> Element


Recommended Posts

Larry,

 

In the HTML form of this chapter:

        <p><label for="gender">Gender: </label>
            <input type="radio" name="gender" value="M"> Male 
            <input type="radio" name="gender" value="F"> Female</p>

I read a book on HTML5, and it says the for="gender" in <label> should refer to the id of the table control, but there is no 'id' in these two <input> tags. I created my HTML5 script in Netbeans when reading this chapter, and noticed Netbeans shows message on this for="gender":

The "for" attribute of the "label" element must refer to a form control.
From line 23, column 12; to line 23, column 31
(Rule Category: All Other)

 

So Is this way of coding XHTML style only?

Link to comment
Share on other sites

Yes, the for attribute should refer to an ID (and all IDs on a page must be unique). As such, when there are multiple radio buttons that make up a set, setting the for attribute for the label element likely does not make any sense to do. I agree with what you are saying.

 

The following may shed some more light on this:

http://stackoverflow.com/questions/13273806/using-the-html-label-tag-with-radio-buttons

Link to comment
Share on other sites

 Share

×
×
  • Create New...