Home arrow JavaScript arrow Page 2 - Universal Form Validation

Universal Form Validation

We have witnessed the wonders of JavaScript and its ability to ensure that our forms are properly filled before submission. But it gets so laborious to type and modify and update form validation scripts for every for in every application. Take heart! Upon reading and applying the methods in this article, you will never again have to worry about client-side validation! Hazzah!

Author Info:
By: Justin Cook
Rating: 4 stars4 stars4 stars4 stars4 stars / 26
February 02, 2004
  1. · Universal Form Validation
  2. · First, the Forms
  3. · Good Form, Jack!
  4. · Pick a Number, Any Number!
  5. · And Knowing is Half the Battle

print this article

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" 
<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" />

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.

blog comments powered by Disqus

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials