I have a checkbox in my html file:
<input type="checkbox" id="kopia" name="kopia" class="form-input" value="0">
I'm trying to pass to the php file (via AJAX) couple of values, one of them is a boolean value created by a checkbox (simplified):
name: "kopia"
value: document.getElementById("kopia").checked
If I check via console
document.getElementById("kopia").checked
it returns true if checked and false if unchecked.
If I check via php file:
echo $_POST['kopia']
it behaves the same.
But when I write something like this:
$checkbox = $_POST['kopia'];
if ($checkbox){
echo "hey";
} else {echo "bye";}
it always returns "hey", no matter if the checkbox was checked or not. I don't get it. Even if I make something like this:
$checkbox = $_POST['kopia'];
if ($checkbox){
echo $checkbox;
} else {echo "bye";}
it never returns "bye", no matter if the box was checked or not, but returns 'true' if checked and 'false' if unchecked. This thing has already stolen couple of hours and that's couple of hours too much. Any idea, hint?
Aucun commentaire:
Enregistrer un commentaire