views:

58

answers:

4

Hi,

I am trying to bulk disable all the submit buttons present in my form. I am getting all the buttons using the following jQuery

jQuery('input')

This returns me an array of the Input tags. I can iterate through this and disable each and every one of them. But is there a better way to perform this operation. Something like,

jQuery('input').disable()
+4  A: 

Like this:

$('input').attr('disabled', true);
SLaks
so sweet!!! Thanks for your instant response!!! This answer does not work. But this worked `jQuery('input').attr('disabled', true);` Can you please edit your answer to reflect this. I will then accept it.
Bragboy
This is going to give you every single input element on the form. If you are only trying to disable submit buttons how about trying: $("input[type='submit']").attr('disabled', true);
tribus
A: 

There is no intrinsic disable function. In the book "Jquery In Action", they created enable and disable methods for the example on how to create a jQueryy plugin, so I've just kept those and used them.

James Curran
+2  A: 

Use attr it works on collections.

jQuery('input[type=submit]').attr('disabled','disabled');
Adam
+2  A: 

You can do it efficiently and easily without jQuery:

var inputs = document.body.getElementsByTagName("input");
for (var i = 0, len = inputs.length; i < len; ++i) {
    if (input.type == "submit") {
        inputs[i].disabled = true;
    }
}
Tim Down