When I use a checkbox which isn't checked, it dosn't post it at all.
When its checked, the value is 1, but how do I make it so when its not checked its value is 0?
When I use a checkbox which isn't checked, it dosn't post it at all.
When its checked, the value is 1, but how do I make it so when its not checked its value is 0?
You mean like:
?PHP Code:<?php
$checkbox = $_POST["checkbox"];
if($checkbox !== "1") {
// do nothing
} else {
echo('You ticked it.');
}
?>
I think that's controlled by the browser, as check-box's were designed for multiple rows, making it more of a "choose-box" (if you buy something from a shop, you would say "I want that", not "I want that one, but not that one, and not that one, and not that one...".
To make the value "0", you can use something like:
Code:<?php $input=$_POST['tos']; if (empty($input)) $input=0; ?>
Want to hide these adverts? Register an account for free!