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

后端 未结 12 755
盖世英雄少女心
盖世英雄少女心 2020-11-22 08:04

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 defa

12条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 08:38

    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.

提交回复
热议问题