I need to get the value of the checkboxes when checked and unchecked and save it in database. The value is 1 if checked and 0 if unchecked, respectively. I am currently using the snippet below and it show the result i want when i alert it. But the problem comes when saving in the database. It still gets the value I have set in my checkbox E.G: value='1'.
Here is my jQuery code:
$(document).ready(function() {
$('input[type="checkbox"]').click(function() {
var val = this.type == "checkbox" ? +this.checked : this.value ;
});
});
Here is my HTML checkbox:
<input type="checkbox" value="1" name="one_by_one" id="one_by_one" class="one_by_one">One
$value = isset($_POST['one_by_one']) ? 1 : 0;. If you are using codeigniter than it might provide helper functions for accessing the data of a request.