Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML HTML Forms Choosing Options Checkboxes

Joseph Torres
Joseph Torres
6,280 Points

Trying to understand importance in naming id and for attributes with the same name and how this ties in the label tag

I know he explains the importance but its not concrete in my mind. Can someone elaborate a little more on this? Thanks

1 Answer

Chris Davis
Chris Davis
16,280 Points

Its not the name attribute that should be the same, it's the #id. When the label is clicked it will pass the focus to the form input element. For example...

<label for="firstName">FirstName</label><br>
<input type="text" name="yourName" id="firstName">

Here is a demonstration https://jsfiddle.net/awrzbabx/ and here is an explanation http://stackoverflow.com/a/18432715

Hope that helps :thumbsup: