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.
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.
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.
var inputs = document.getElementsByTagName("INPUT");
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type === 'submit') {
inputs[i].disabled = true;
}
}
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';
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With