1

I use the following to disable all form elements within a table row:

$(".chkbx").change(function(){ var $this = $(this); if ($this.is(":checked")) { $this.closest("tr").find(":input").attr("disabled", false); } else { $this.closest("tr").find(":input").attr("disabled", true); } }); 

Which it does great. The problem -- it disables ALL, including .chkbx. I need to keep the checkbox with this class (chkbx) always enabled. How do I exclude it from the function?

1
  • 2
    $this.closest("tr").find(":input:not(.chkbx)")? Or $this.closest("tr").find(":input").not('.chkbx')? Commented Nov 30, 2011 at 2:03

4 Answers 4

4

I think using the not function like this would work

$this.closest("tr").find(":input").not(".chkbx").attr("disabled", true); 
Sign up to request clarification or add additional context in comments.

Comments

1

Add one more line to your existing code:

$(".chkbx").change(function(){ var $this = $(this); if ($this.is(":checked")) { $this.closest("tr").find(":input").attr("disabled", false); } else { $this.closest("tr").find(":input").attr("disabled", true); } $this.attr("disabled",false); }); 

It's not optimal or efficient, but it should work.

Comments

0

how about this:

$(".chkbx").change(function(){ var $this = $(this); if ($this.is(":checked")) { $this.closest("tr").find(":input").attr("disabled", false); } else { $this.closest("tr").find(":input:not(.chkbx)").attr("disabled", true); } }); 

not sure if it will work! but give it a try!

Comments

0

I'd suggest something like the following:

$('.chkbx').change( function(){ if ($(this).is(':checked')){ $(this).closest('tr').find('input,textarea,select').not($(this)).attr('disabled',true); } else { $(this).closest('tr').find('input,textarea,select').not($(this)).attr('disabled',false); } }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.