Alessandro Lacava’s Blog

Google
 

March 31, 2008

How to disable all the elements of a form using JavaScript

Filed under: Computer, JavaScript — alessandrolacava @ 3:41 pm

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

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

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