If a checkbox is unchecked when its form is submitted, there is no value submitted to the server to represent its unchecked state (e.g. value=unchecked
); the value is not submitted to the server at all.
If you wanted to submit a default value for the checkbox when it is unchecked, you could include an <input type="hidden">
inside the form with the same name
and a value
of false
for example.
<form>
<input type='hidden' name='selfdestruct' value='0'>
<input type='checkbox' name='selfdestruct' value='1'>
</form>
...doesn't work for me because it's using name
as a key and value
as that key's value, whereas I need name
to be the identifier, value
to be the key and somehow always get that key's value as true or false.
I've got around 200 checkboxes that represent a user's weekly availability, like so:
<div>
<fieldset>
<legend>Monday</legend>
<label>7 - 8
<input type="checkbox" name="schedule" value="Monday-7" />
</label>
<label>8 - 9
<input type="checkbox" name="schedule" value="Monday-8" />
</label>
...
</fieldset>
<fieldset>
<legend>Tuesday</legend>
<label>7 - 8
<input type="checkbox" name="schedule" value="Tuesday-7" />
</label>
<label>8 - 9
<input type="checkbox" name="schedule" value="Tuesday-8" />
</label>
...
</fieldset>
...
</div>