Do checkbox inputs only post data if they're checked?

Mark picture Mark · Jul 11, 2012 · Viewed 253.6k times · Source

Is it standard behaviour for browsers to only send the checkbox input value data if it is checked upon form submission?

And if no value data is supplied, is the default value always "on"?

Assuming the above is correct, is this consistent behaviour across all browsers?

Answer

John C picture John C · Jul 11, 2012

Yes, standard behaviour is the value is only sent if the checkbox is checked. This typically means you need to have a way of remembering what checkboxes you are expecting on the server side since not all the data comes back from the form.

The default value is always "on", this should be consistent across browsers.

This is covered in the W3C HTML 4 recommendation:

Checkboxes (and radio buttons) are on/off switches that may be toggled by the user. A switch is "on" when the control element's checked attribute is set. When a form is submitted, only "on" checkbox controls can become successful.