Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable all input buttons without using jQuery?

Tags:

javascript

dom

How would I do this without jQuery?

$('input[type=submit]').attr('disabled',true);

It doesn't have to be cross-browser compatible; a solution that only works in Firefox is OK.

like image 899
Kip Avatar asked Jul 29 '09 18:07

Kip


People also ask

How do I disable all input fields?

To disable all form elements inside 'target', use the :input selector which matches all input, textarea, select and button elements. $("#target :input"). prop("disabled", true); If you only want the elements, use this.

How do you make a whole form disabled?

To disable all form controls within a fieldset , use the disabled attribute like this <fieldset disabled> . You probably already have some CSS styling that should apply to disabled form controls. This usually also works within a field set without changing anything.


2 Answers

var inputs = document.getElementsByTagName("INPUT");
for (var i = 0; i < inputs.length; i++) {
    if (inputs[i].type === 'submit') {
        inputs[i].disabled = true;
    }
}
like image 80
RaYell Avatar answered Oct 05 '22 23:10

RaYell


Have you tried

document.getElementsByTagName("input");

then you could interrogate the DOM to find your submit button. getElementsByTagName reference

A full sample

window.onload = function(e) {
    var forms = document.getElementsByTagName('form');
    for (var i = 0; i < forms.length; i++) {
        var input = forms[i].getElementsByTagName('input');
        for (var y = 0; y < input.length; y++) {
            if (input[y].type == 'submit') {
                input[y].disabled = 'disabled';
            }
        }

    }
}
like image 24
David Christiansen Avatar answered Oct 06 '22 01:10

David Christiansen