JavaScript
  Home arrow JavaScript arrow Page 2 - Universal Form Validation
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Universal Form Validation
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 24
    2004-02-02

    Table of Contents:
  • Universal Form Validation
  • First, the Forms
  • Good Form, Jack!
  • Pick a Number, Any Number!
  • And Knowing is Half the Battle

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Universal Form Validation - First, the Forms


    (Page 2 of 5 )

    Let’s have a quick preview of what the code will now be in all forms to ensure the script will work.


    <script language="JavaScript" 
    type
    ="text/javascript" 
    src
    ="/includes/forms.js">
    </script>
     
    <form name="form1" action="/mailer.asp" 
      method="post" onsubmit="return 
      checkForm( document.form1 )">
    <input type="text" name="name_required" />
    <input type="text" name="email_required" />
    <input type="text" name="age_required" 
     onkeypress="return checkInt( event )" />
    <input type="text" name="comments" />
    <input type="submit" />
    </form>

    So you’ve cleverly deuced that the JavaScript functions will be contained in one big container file called ‘forms.js’. Whenever we have a form that needs validating, all that need be done is a simple inclusion of this script file, and the attaching of ‘_required’ to the end of any… you guessed it, required fields! Oh, and one more thing.

    We need to tell the client browser that when the user is done filling out the form, please verify it before sending to the server. This is accomplished by the onsubmit handler.

    But what was that whole mess with the age field? We’ll deal with that a little bit later, for now let’s delve into the workings of the actual checkForm function.

    More JavaScript Articles
    More By Justin Cook


     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT