This article assumes a general understanding of HTML and Java Script.
(16 printed pages) Introduction Getting Started Writing the Validation Script Connecting the Form to the Script Associating Form Fields with Custom Script Code Listing Conclusion When you create forms, providing form validation is useful to ensure that your customers enter valid and complete data.
by Christopher Heng, Many websites, like thesitewizard.com, have a feedback form of some sort so that visitors can make comments to the webmasters.
If you have such a form on your site, I'm sure that from time to time, you would have received the results of your form with some essential field (like the email address or the visitor's name, or even the feedback itself) omitted. One way around it is to validate the essential fields with a simple Java Script.
In this article we intend to present only a number of simple examples to get you started, covering the basic form elements.
Before you ask, and someone always does, these examples will currently work in the following browsers: Safari 5, Chrome 6, Opera 9, Firefox 4 Beta and the i Phone/i Pad.
It can prevent people from leaving fields blank, from entering too little or too much or from using invalid characters.
For an alternative approach to client-side form validation, without Java Script, check out our new article on HTML5 Form Validation which is available now in most modern browsers.A better solution is to use Java Script to validate each field on the client browser as the user enters data and if necessary carry out any mathematical calculation, without the need to submit the page, thereby speeding up the data entry process.Validating form input with Java Script is easy to do and can save a lot of unnecessary calls to the server as all processing is handled by the web browser.To make the web browser check that a field is not empty, you will need to add a call to your validation function when the form is submitted.The option of using pure HTML, sometimes with a touch of CSS, to complement Java Script form validation was until recently unthinkable.Also each browser has a slightly different default behaviour.