JAVASCRIPT - Simple function to reset all form elements
 
Rating: 3 user(s) have rated this article 5.0 out of 5 stars
Posted by: chimaera, on 8/28/2009, in category "Javascript"
Views: this article has been read 394 times


Delicious Bookmark this on Delicious

Here's a simple javascript function that you can call to reset all elements in a form:

 

  function ClearForm ()
  {
        var thisForm = document.forms[0];


        for(i=0; i < thisForm.elements.length; i++ )
        {

               if ( thisForm.elements[i].type == "text"
                                             || thisForm.elements[i].type == "textarea" )
               {
                      thisForm.elements[i].value = "";

               }
               else if (thisForm.elements[i].type == "select-one")
              {
                       thisForm.elements[i].selectedIndex = 0;
               }

         }
   }

 

 In this example I reset the first form and I reset textboxes, textarea's and select's.

Example

First name:
Last name:
Name Suffix:

 

 

Share and Bookmark

LinkedIn Google Del.icio.us Digg Reddit Stumble Upon

DISCLAIMER: This information is provided "as is". The author, publishers and marketers of this information disclaim any loss or liability, either directly or indirectly as a consequence of applying the information presented herein, or in regard to the use and application of said information. No guarantee is given, either expressed or implied, in regard to the merchantability, accuracy, or acceptability of the information.


How would you rate this article?

User Feedback

Post your comment
Name:
Comment:
Insert Cancel
Questions...
Have you upgraded to Windows 7?


Archived Polls