Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to perform events when a checkbox is checked/unchecked in jquery

Tags:

jquery

I have the following jquery code which works fine.

$('#onlyTwo').click(function() {
                $("#textarea3").attr("disabled", true);
                $("#textarea4").attr("disabled", true);
                $("#radio3").attr("disabled", true);
                $("#radio4").attr("disabled", true);
                return true;
            });

This is making some fields disabled when 'onlyTwo' checkbox is clicked. How can i make these fields enabed again when 'onlyTwo' checkbox is unchecked...

basically i want to know how to find out whether a checkbox is checked or not

like image 987
n00bstackie Avatar asked May 27 '09 18:05

n00bstackie


2 Answers

or

$('#onlyTwo').click(function(){
   var stuff = $("#textarea3,  #textarea4, #radio3, #radio4");
   stuff.attr("disabled", $(this).is(":checked"));
});
like image 105
mkoryak Avatar answered Sep 22 '22 01:09

mkoryak


$('#onlyTwo').change(function() {
    $('.disableMe').attr('disabled', $(this).is(':checked'));
});

so you need to add 'disableMe' class to all the inputs, textareas, selects... that you wish to disable.

like image 44
coma Avatar answered Sep 19 '22 01:09

coma