How to disable all the elements of a form using JavaScript

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

  
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 powered by Disqus