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! Mozilla
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.
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.