Friday, April 30, 2010

jQuery - check/uncheck a checkbox

$('#PrimaryContacts').unbind().change(function() {
if ($('#PrimaryContacts option:selected').val() == 0) {
$('#filterPrimaryContact').removeAttr('checked').trigger('click');
}
else {
$('#filterPrimaryContact').trigger('click');
}

});


Also, in the example above, triggering the checkbox does not change the checkbox value. As depicted above, based on a dropdown box changing and no contact being selected from the drop down box, automatically uncheck the checkbox and trigger it in invoke any event handlers on the checkbox.