When I submit a HTML form with a checked checkbox that doesn't have an explicitly defined value
, Chrome sends on
as a value for that field.
Is that the standard behavior? Or what can I expect from other browsers?
Use the defaultChecked prop to set the default checked value of a checkbox in React, e.g. defaultChecked={true} . Input elements with type set to checkbox support the defaultChecked prop for setting a default value. Copied!
The defaultChecked property returns the default value of the checked attribute. This property returns true if the checkbox is checked by default, otherwise it returns false.
The HTML 4.01 specification does not specify the value of a checked checkbox. It just refers it saying that it is “on”, but this is just prose and does not say what the default value is. But it also says (under the description of the input element) that the value attribute is required in this case.
The HTML 4.01 specification does not specify the value of a checked checkbox. It just refers it saying that it is “on”, but this is just prose and does not say what the default value is. But it also says (under the description of the input
element) that the value
attribute is required in this case.
So <input type=checkbox name=foo>
has undefined behavior as regards to the value used, though in practice browsers use value=on
as the default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With