How to enable button when checkbox clicked in jquery ?
A:
$('input:checkbox').bind('change', function(){
if($(this).is(':checked'))
$('input:button').removeAttr('disabled');
});
jAndy
2010-08-25 12:15:34
A:
$("#yourcheckboxid").click(function() {
var checked_status = this.checked;
if (checked_status == true) {
$("#yourbuttonid").removeAttr("disabled");
} else {
$("#yourbuttonid").attr("disabled", "disabled");
}
});
Tim
2010-08-25 12:17:18
+2
A:
You can do it like this:
$("#checkBoxID").click(function() {
$("#buttonID").attr("disabled", !this.checked);
});
This enables when checked, and disables again if you uncheck. In jQuery .attr("disabled", bool) takes a boolean, so you can keep this pretty short using the this.checked DOM property of the checkbox.
Nick Craver
2010-08-25 12:18:53
+1 for the negating the boolean, it's a simple technique that isn't used enough, IMO. Oh, and not using *.is(":checked")*, too ;-)
Andy E
2010-08-25 12:22:41