mardi 28 février 2017

array only storing checkboxes with value 1 (not 0)

I have checkboxes which change value using JavaScript and I want to store values of all checkboxes in a PHP array. But if the user changes the value of one checkbox to "0", the array created has only 2 values (1,1) instead of (1,0,1).

HTML

<input type="checkbox" name="cbox1[]" checked="checked" value="1" class="chbo">
<input type="checkbox" name="cbox1[]" checked="checked" value="1" class="chbo">
<input type="checkbox" name="cbox1[]" checked="checked" value="1" class="chbo">

PHP

$wer=$_POST['cbox1'];
echo implode(",",$wer);

Jquery

$(document).on('click', '.chbo', function() {
this.value ^= 1;
console.log(this.value);
});




Aucun commentaire:

Enregistrer un commentaire