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

Why do we need the name attribute for HTML checkbox?

I understand we need the name attribute for radio buttons. This makes sure that multiple buttons are in the same group.

In the case of check box why do we need the name attribute? Check boxes doesn't need to be grouped so what is the use of the name attribute for them?

1 Answer

Forms are submitted, when forms are submitted the elements are processed based on their names.
In addition, it's also useful to use names related to a database where the data is going. Using checkboxes with the same name means your code can easily figure out where the information goes (like, 'interests', or 'pets') in the database

Thanks John, that makes sense.