Why do Checkboxes need the same 'name' attribute?

Beginner question:

Why is it that when we’re creating checkboxes we need to make sure that the name attribute is same for all our checkboxes within the form?

I understand that for radio buttons for example, the name attribute must match so they’re all part of the same group allowing the user of the webpage to only select one value as an answer but as far as I’m aware this isn’t the case with checkboxes and the user can select multiple answers that apply to them.

So why is it that checkboxes still require the same name attribute when it’s not necessary for them to be in the same group - unless I’ve missed something and if it is necessary, please explain why.

Thanks in advance to anyone who can provide a little clarification on this.

1 Like

All ‘related’ checkboxes should have the same name value.

The name attribute for checkboxes, similar to radios, groups those checkboxes together. The checked checkboxes are sent from the form as a group to the server to be parsed for their values.

For instance, if you had multiple checkboxes pertaining to 1 category of a survey, when the form for the survey was submitted to the server, all the checked values for that category will be grouped together (array) and can be accessed as such.

It’s usually only truly relevant server side and can otherwise be completely omitted.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.