I have a form with many checkboxes, and a PHP page is called for updating the database on each click.
HTML
<form>
<input type="checkbox" name="status1" id="event_status1" value="1" >
<input type="checkbox" name="status2" id="event_status2" value="1" >
<input type="checkbox" name="status3" id="event_status3" value="1" >
</form>
JQuery
$('input:checkbox').change(function(e) {
e.preventDefault();
var isChecked = $("input:checkbox").is(":checked") ? 1:0;
$.ajax({
type: 'POST',
url: "admin-ajax.php",
data: { event_status:$("input:checkbox").attr("id"), status:isChecked},
success: function (response) {
console.log(response);
}
});
});
It works well when I check/uncheck each checkbox individualy.
If I check the 3 boxes, the last I have checked won't send "0" status if I uncheck it but wil always send "1".
Aucun commentaire:
Enregistrer un commentaire