Using JavaScript for Form Validation

Although this book is about CGI programming, I want to talk a bit about JavaScript—the first line of defense for validating user input. The most important thing to remember about using JavaScript to validate forms is that it’s not completely reliable. In other words, you must validate the form content on the server side as well.

There are two advantages to using JavaScript to validate forms. One works to the benefit of the user, and the other works to the benefit of the systems administrator. Users benefit because JavaScript provides instant feedback. You can set up your form validation so that it tests the value in a form field the moment the user leaves that field, or before the form is submitted. Either ...

Get Sams Teach Yourself CGI in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.