tags:

views:

33

answers:

3

How to enable button when checkbox clicked in jquery ?

A: 
$('input:checkbox').bind('change', function(){
  if($(this).is(':checked'))
     $('input:button').removeAttr('disabled');
});
jAndy
A: 
$("#yourcheckboxid").click(function() {
    var checked_status = this.checked;
    if (checked_status == true) {
       $("#yourbuttonid").removeAttr("disabled");
    } else {
       $("#yourbuttonid").attr("disabled", "disabled");
    }
});
Tim
+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
+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