How to disable all elements on a form !!

Started by ram, Aug 12, 2008, 11:08 AM

Previous topic - Next topic

ram

Hi [you],

How to disable all elements on a form

You can have your form to be disabled as soon as the user pressed the submit button so that he doesn't accidently submit the form twice. This is the code you can use.

<HTML>
<HEAD>

<script>
   function disableForm(theform) {
      if (document.all || document.getElementById) {
         for (i = 0; i < theform.length; i++) {
         var formElement = theform.elements;
            if (true) {
               formElement.disabled = true;
            }
         }
      }
   }
</script>

</HEAD>

<BODY>

   <form method="post" action="http://www.s64df.com" onSubmit="return disableForm(this);">
      <input type="text" name="Text1">
      <input type="submit" name="SubmitButton" value="Submit">
   </form>
   
</BODY>
</HTML>