Once you have an HTML form up and running, you will often want to make sure that all the important fields are filled in. For example, if you are going to send an email confirmation letter, the email address should be included in the form fields, and it should be an email address that works.
There are two ways to validate your forms:
- Using JavaScript
- Using a CGI script
Pros and Cons of Using JavaScript for Validating Forms
Pros
- Using JavaScript you don't use any server processor time. All the processing is done on the client computer.
- It often appears to work faster than the CGI validation.
- Since the form page has not changed, it is easy for the reader to fix the errors.
Cons
- JavaScript only works on browsers that have it enabled. If the JavaScript is disabled, your error checking doesn't get done.
Pros and Cons of Using CGI for Validating Forms
Pros
- Using a CGI to validate ensures that every time the form is submitted, the validation will run.
Cons
- CGI puts more load on the Web server, and every function that is included in the CGI is one more task for the server.
- CGI can be slow to run.
- If there is an error, the customer has to either go back to the first page of the form, or the CGI needs another function to rewrite the form page.
The way I handle this is to have the majority of the error checking done with JavaScript. That way, it is fast and easy for the readers. I then recheck the vital elements of the form with the CGI.
Page 2: How to Use JavaScript to Validate HTML Forms
This article is part of the HTML Forms Tutorial

