How to Checkbox value 0 or 1 using jquery


jquery tutorial

If you have a checkbox in a form you can use jQuery to read and set the data 0 or 1 in the checkbox.

When using jQuery and you wish to read whether a checkbox is checked or not the checked value 1 and unchecked value 0.

Here is the HTML we’ll use an example for our checkbox.

<input type="checkbox" name="current_day" value="0" id="current_day"  />

Jquery change event set 0 or 1 value (checked = 1 and unchecked = 0)

$('#current_day').on('change', function(){
   this.value = this.checked ? 1 : 0;