I am trying to update a value in DB while checking checkbox (1 or 0) with jquerys $.post or $.ajax. I would really appreciate some help. Here is my code:
HTML
<div class="onoffswitch">
<?php
$yesno = (bool)$baner['noti'];
$checked = ($yesno) ? 'checked="checked"' : '';
?>
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" value="1" id="myonoffswitch" <?php echo $checked; ?>>
<label class="onoffswitch-label" for="myonoffswitch"></label>
</div>
jQuery
$(function(){
$("#myonoffswitch").click(function(){
$.post("notification.php");
})
});
notification.php
connections stuffs...
$yesno = ( isset($_POST['onoffswitch']) ) ? 1 : 0;
$sql = "UPDATE baner SET noti='$yesno'";
post()helpful, especially the examples.