Creating checkboxes in a form

Dear Campers,
I have been teaching myself how to create a survey form in HTML5 from various sites including freeCodeCamp , however i have failed to make sense of the value attribute when creating radio buttons and check boxes. I thought the value of the value attribute is what is submitted to the backend for processing when a user submits the form for example:

<form> <input id = "male" type = "radio" name = "gender" value = "Male" > </form

However some of the tutorials tend to ignore the value attribute. How then does the browser know what value to associate with the name attribute gender when sending the form form for processing to the backend?

As far as ‘good code practices’ go, always include a value attribute with a value.

As for other tutorials excluding it: if value is omitted, the form will submit, and the data can be processed, provided the from is simple enough, and the back-end can handle the fact that there will be no unique identifier to go along with it.

If you omit the value attribute in the HTML, the submitted form data assigns the value on to the group. In this scenario, if the user clicked on the “Phone” option and submitted the form, the resulting form data would be contact=on , which isn’t helpful. So don’t forget to set your value attributes!

The value of on automatically assigned to the button allows the form to be handled, because this will ‘uniquely’ identify which radio has been selected.

Hope this helps.

1 Like

Thanks for the response. Actually FCC also doesn’t include the value attribute (at least as far as the tutorials i have gone through are concerned). Hopefully it isn’t an oversight.