I am using the following code to sync 2 input boxes.
$("#input_box_1").bind("keyup paste", function() {
$("#input_box_2").val($(this).val());
});
The above works great but I need to do the same for a checkbox.
My question is…how do I modify the code for it to work with a checkbox?
You need to modify the
checkedproperty according to the value of that property on the first checkbox whenever the first checkbox changes (so we bind to thechangeevent):Note that you don’t need to pass
thisinto jQuery, you can just access the property of the raw DOM element, which is faster.