Book Image

Learning jQuery : Better Interaction Design and Web Development with Simple JavaScript Techniques

Book Image

Learning jQuery : Better Interaction Design and Web Development with Simple JavaScript Techniques

Overview of this book

Table of Contents (18 chapters)
Learning jQuery
Credits
About the Authors
About the Reviewers
Preface

Form Validation


Before we add validation to any form with jQuery, we need to remember one important rule: client-side validation is not a substitute for server-side validation. Again, we cannot rely on users to have JavaScript enabled. If we truly require certain fields to be entered, or to be entered in a particular format, JavaScript alone can’t guarantee the result we demand. Some users prefer not to enable JavaScript, some devices simply don’t support it, and a few users could intentionally submit malicious data by circumventing JavaScript restrictions.

Immediate Feedback

Why then should we bother implementing validation with jQuery? Client-side form validation using jQuery can offer one advantage over server-side validation: immediate feedback. Server-side code, whether it’s ASP, PHP, or any other fancy acronym, needs the page to be reloaded to take effect (unless it is accessed asynchronously, of course, which in any case requires JavaScript). With jQuery, we can capitalize on the peppy...