I have some code
<input type="checkbox" id="chk" value="value" /> <label for="chk">Value </label> <br/> <input type="button" id="But1" value="set value" /> <br /> <input type="button" id="But2" value="read checked" />
javascript:
$(document).ready(function () { console.log("Ready ..."); registerHandlers(); function registerHandlers() { $('#But1').click(function () { $('#chk').prop('checked', !$('#chk').is(':checked')); }); $('#But2').click(function () { var chk1 = $('#chk').is(':checked'); console.log("Value : " + chk1); }); $('input[type="checkbox"]').change(function () { var name = $(this).val(); var check = $(this).prop('checked'); console.log("Change: " + name + " to " + check); }); } });
How to handle change of checkbox using jQuery ? I need to put the handler to change any checkboxes checked.
[update]
There is a checkbox and a few buttons. Each button can change check box. How to catch an event changing the checkbox?
[Update]
I need handle change checkbox in this example jsfiddle. When I click on the box the message "OK" button is not shown.
change() updates the textbox value with the checkbox status. I use . click() to confirm the action on uncheck. If the user selects cancel, the checkmark is restored but .
“jquery check if checkbox is checked onchange” Code Answer's$( "SELECTOR" ). prop( "checked" ) // Returns true if checked, false if unchecked. $( "SELECTOR" ).is( ":checked" ) // Returns true if checked, false if unchecked.
$("#checkbox1"). prop('checked', true);
Use :checkbox
selector:
$(':checkbox').change(function() { // do stuff here. It will fire on any checkbox change });
Code: http://jsfiddle.net/s6fe9/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With