'What is the purpose of the `name` attribute in a checkbox input element?

I went through many online documents for the checkbox input in XHTML. Can anyone clear my doubt? What does this name field actually stand for?

Milk: <input type="checkbox" name="checkbox" value="Milk">
Chocolate: <input type="checkbox" name="checkbox" value="chocolate">
Cold Drink: <input type="checkbox" name="checkbox" value="Cold Drink">

I thought it was an identifier for that particular checkbox, which can later be used in other file by just referring their name, but given that all the checkbox had same name, why even specify it? A little confused of this.



Solution 1:[1]

The name attribute is used to reference form data after it’s submitted, and to reference the data using JavaScript on the client side.

Source: http://reference.sitepoint.com/html/input/name

Basically, what you've described. When the form is submitted, you can access the values of the form elements through the name you ascribe to them.

The only place where you would want to have multiple inputs with the same name is when they are radio buttons, in which case it is used to indicate which one of them belongs to the same group and thus only one of which can be selected at a time.

Solution 2:[2]

The name attribute is used to identify a checkbox. Which you could parse into a object like so {checkboxName1: 'checkboxValue2', checkboxName2: 'checkboxValue2'}

Solution 3:[3]

the "name" is same with the databse record, every field should have a name, so when you click the submit, the data will recorded to the database~~~~~

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yi Jiang
Solution 2 Jonathan Otokun
Solution 3 Matthew Ma