|
||
| Inside Technique : Form Validation Made Easy As a web developer, you are often required to perform the same tasks repeatedly across pages and entire sites. One of the most tedious such task is form validation. Every form requires something a little different, whether requiring specific fields, checking dates or making sure someone entered a phone number correctly. I included two different techniques for adding form validation. The first runs only on Internet Explorer 4.0 or later while the latter approach runs cross-browser. The IE-only technique is simpler to use and more powerful and is presented first. To support the same level of validation cross-browser support additional scripting is necessary. The cross-browser version is covered later in this article. I have assembled a script which takes advantage of the document object model (DOM) available in Internet Explorer 4 and 5. As such, this script is only useful within applications targeted solely at these browsers. It will not cause problems in other browsers, but it won't perform its miracles, either. The key techniques which represent the bulk of the script are as follows:
By combining the above techniques with others already discussed at this site, my script can perform pre-defined field validation without any added code. Since I can't predict all the different types of validation you may need to use, I also created a framework in which you can easily add more of your own checks, which work in tandem with mine. I have assumed a general understanding of JavaScript/JScript throughout the article. I refer you back to the many tutorials on SiteExperts.com if you get lost anywhere along the way. Let's start by looking at expando properties. Page 1:Form Validation Made Easy © 1997-2000 InsideDHTML.com, LLC. All rights reserved. |