I'm trying for days to solve this problem, but with no results so far...
All I want to do is to POST checkbox value to php when the user check or uncheck it.
form.php:
<?php
if (isset($_POST['box'])) {
echo $_POST['box'];
} ?>
Script:
<script>
$(document).ready(function() {
$('.box').on('change', function(event) {
var checkbox = $(event.target);
var isChecked = $(checkbox).is(':checked');
$.post('/form.php', {id: checkbox.attr('id'), value: isChecked});
});
});
</script> //Credit cymen
Form:
<form action="form.php" method="post">
<input id="box" class="box" name="box" type="checkbox" value="YESSSSSS!" />
<input id="box" class="box" name="box" type="checkbox" value="YESSSSSS!" />
</form>
(*) I get nothing on $_POST['box']
nameattribute of the input corresponds to the request parameter that contains its value when you post the form.idis never sent to the server, only itsnameandvalue. For what you're doing here, there's no need for anidbecause you're using the class name to select the checkboxes.