tags:

views:

51

answers:

2
$(this).closest("fieldset").find("input:not(:checkbox), select,textarea").attr('disabled', this.checked);  

with this I can Disable Input,select,textarea how to do with the button?

thanks

+1  A: 

Not quite - as long as the disabled attribute is present, the control will be disabled. To re-enable the control, you have to remove the disabled attribute. Something like this:

var element = $(this).closest("fieldset").find("input:not(:checkbox), select,textarea");
if (this.checked) {
  element.attr('disabled', 'disabled');
} else {
  element.removeAttr('disabled');
}
Harold1983-
It is a good practice to remove the `disabled` attribute, but not required to my knowledge. Setting true/false (which is what OP is doing) should work too.
patrick dw
I need to disble type="submit'<input id="IbtnSubmit" type="submit" class="button" value="Save" />
+2  A: 

Your code works for me:

Try it out: http://jsfiddle.net/JzKdx/2/ (updated)

Were you having some specific issue?

HTML (updated to include submit button)

<fieldset>

    <input type='checkbox' /> Click me
    <br><br>
    <input type='text' />
    <select>
        <option>one</option>
    </select>
    <textarea>
        sometext
    </textarea>

    <input type='submit' />

</fieldset>

jQuery

$(':checkbox').change(function() {
    $(this).closest("fieldset")
        .find("input:not(:checkbox), select,textarea")
        .attr('disabled', this.checked);  
    });​
patrick dw
Yes pat I do see that. i will try