I noticed when learning inputs where type=“checkbox”, that “value” is defined in the code. I thought that “value” is not typically defined in the code - since the “value” is what a user would enter into our form, not what is written into our code.
Is defining the “value” in the code something we do here because this input type=“checkbox”? (I.e. do we have to define the value for all checkboxes?) Or is this more related to how we group our checkboxes?
If I remember correctly, checkboxes has
"on" as default value, we can change this default value to anything we like using
value attribute. The value attribute for checkboxes determines the value send on a checked checkbox.
this differs from the
value attribute for a
<input type="text" for example, where
value would set the default value for the input field which can then be overwritten by the user. Sometimes setting default values can be useful
given checkboxes have a default value, we don’t have to include the value attribute.