I have a a checkbox like so:
<label for="TBMasterProduct.BloodTestEnabled">Blood Test Enabled?</label>
<input type="checkbox" name="TBMasterProduct.BloodTestEnabled" id="TBMasterProduct_BloodTestEnabled" class="cb" />
When I submit the form its sending the value ‘on’ against TBMasterProduct.BloodTestEnabled
Why would a checkbox post that value? Surely it should be true/false
Browsers default to a value of
onif you don’t set one explicitly with avalueattribute.At the time this answer was written, this was non-standard error recovery. In HTML 4, the
valueattribute is mandatory for checkboxes. HTML 5 makes the attribute optional with a default ofon.No. Either the checkbox is checked (and thus successful) so the value gets submitted, or it isn’t and the checkbox doesn’t appear in the submitted data at all.
An individual checkbox may have a boolean state, but multiple inputs can share a name to group them. The values then distinguish which items in the list were selected.