I'm just starting to learn internet programming.
After playing around with checkboxes, I found out the hard way, that it is only when the checkbox is checked that it transmits an 'on' value.
Why not also send an 'off' value?
Return Value: It returns a string value that represents the value of the value attribute of a input checkbox field.
<input type="checkbox">
Rendering Checkboxes Checked By DefaultThere is no required value for the checked attribute. However, per the checkbox specification only an empty value or 'checked' are valid. When checked is added to the checkbox element the browser will render it as selected.
It is possible to have many checkboxes with the same element name:
<form action="order.php" method="get">
<p>
<label><input type="checkbox" name="toppings" value="olives"/>Olives</label>
<label><input type="checkbox" name="toppings" value="mushrooms"/>Mushrooms</label>
<label><input type="checkbox" name="toppings" value="onions"/>Onions</label>
<label><input type="checkbox" name="toppings" value="eggplant"/>Eggplant</label>
etc...
</p>
<p><input type="submit" value="Submit"/></p>
</form>
The url will later include only the checked values and will look something like:
order.php?toppings=mushrooms&toppings=onions&toppings=eggplant
This would have not worked well if an "off" value was sent as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With