squirc77
squirc77

Reputation: 73

Checkbox to enable and disable input tags

I have a checkbox that I want to enable/disable input tags. All of the examples I find use the click event and it works one time, but I would like it to work as a toggle. When I replace toggle with click the checkbox disappears. I'd appreciate an explanation as to why it works this way and what I can add to my code to get it to work as a toggle. Many thanks.

Here is my jsFiddle: <http://jsfiddle.net/squirc77/JAafq>

Upvotes: 0

Views: 462

Answers (2)

user571545
user571545

Reputation:

Try this, it will work over and over:

$(':checkbox').click(function(){
    $('input').not(':checkbox').attr('disabled',!this.checked)
});

Upvotes: 0

Supriti Panda
Supriti Panda

Reputation: 1291

Please try this. It will work.

$(':checkbox').click(function(){
    $('input:radio').attr('disabled',!this.checked)
});

The problem in your code is you are disabling all input box, which disable your checkbox as well.

Check my jsfiddle. http://jsfiddle.net/supriti/JAafq/11/

Upvotes: 2

Related Questions