Alessandro Lacava

on Designing and Developing Software. In love with Functional Programming.

How to Disable All the Elements of a Form Using JavaScript

Here’s a little JavaScript function that disables all form elements:

1
2
3
4
5
6
function disableElements(formName) {
  var fm = document.forms[formName];
  for(var i = 0; i < fm.elements.length; ++i) {
    fm.elements[i].disabled = true;
  }
}

As you may have noticed the only parameter you need to pass is the form name.

Comments