Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

How to Checkbox value 0 or 1 using jquery

by
Category:javascript
javascript
How to Checkbox value 0 or 1 using jquery

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;
});

0 Comments


Html code work in comment box


Related Post