Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML: Checkbox default value

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?

like image 765
Franz Avatar asked Oct 16 '12 09:10

Franz


People also ask

How do I set a default checkbox value?

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!

How do I check if a checkbox is default in HTML?

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.

What is the default value submitted for a checkbox when checked?

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.


1 Answers

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.

like image 102
Jukka K. Korpela Avatar answered Oct 11 '22 04:10

Jukka K. Korpela