Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable button when checkbox clicked in jQuery?

Tags:

How to enable button when checkbox clicked in jQuery?

like image 538
ktm Avatar asked Aug 25 '10 12:08

ktm


2 Answers

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.

like image 168
Nick Craver Avatar answered Sep 18 '22 09:09

Nick Craver


$("#yourcheckboxid").click(function() {     var checked_status = this.checked;     if (checked_status == true) {        $("#yourbuttonid").removeAttr("disabled");     } else {        $("#yourbuttonid").attr("disabled", "disabled");     } }); 
like image 31
Tim Avatar answered Sep 19 '22 09:09

Tim