aeq aeq - 1 year ago 128
HTML Question

jQuery checkbox event handling

I have the following:

<form id="myform">
<input type="checkbox" name="check1" value="check1">
<input type="checkbox" name="check2" value="check2">

How do I use jQuery to capture any check event occuring in
and tell which checkbox was toggled (and know if it was toggled on or off)?

Answer Source
$('#myform :checkbox').change(function() {
    // $this will contain a reference to the checkbox   
    if (this.checked) {
        // the checkbox was checked 
    } else {
        // the checkbox was unchecked
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download