I have a list of checkboxes and i'm trying to limit to 2 maximum checkboxes by disabling all unchecked checkboxes after 2 have been selected.
This works fine, but i'm trying to display a message to the user if they click on a disabled checkbox to let them know why can't select more than 2. I'm trying to fire a click()
event on a disabled checkbox but it doesn't actually fire. Any ideas?
var totalChecked = 0;
var checkedLimit = 1;
jQuery(".post-to-facebook").change(function() {
if (jQuery(this).attr("checked") == "checked") {
if (totalChecked < checkedLimit) {
totalChecked += 1;
if (totalChecked == checkedLimit) {
jQuery(".post-to-facebook[checked!='checked']").attr("disabled", true);
}
} else {
jQuery(this).attr("checked", false);
alert("You can only post twice to Facebook at one time. This is to avoid spam complaints, we don't want to spam on your page!");
}
} else {
totalChecked -= 1;
if (totalChecked < checkedLimit) {
jQuery(".post-to-facebook[checked!='checked']").attr("disabled", false);
}
}
console.log(totalChecked);
});
// THIS DOES NOT FIRE
jQuery(".post-to-facebook:disabled").click(function() {
alert("You can only post twice to Facebook at one time. This is to avoid spam complaints, we don't want to spam on your page!");
});