O'Reilly logo

PHP jQuery Cookbook by Vijay Joshi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Checking for empty fields using jQuery

Validation is an important technique in client-side scripting. Validation on the client side can significantly reduce round trips to the server by providing instant feedback in the form of messages. Even so, it is NOT recommended to rely on the client-side validation alone. JavaScript on the users' browsers might be turned off; therefore, validation should ALWAYS be done again on the server side as well.

How to do it...

  1. Create a file for this recipe and name it index.html. Create a form with some text fields and an input button. Note that all textboxes except city has a class name required assigned to them. This will be used while validating the fields.
    <html> <head> <title>Validate empty fields</title> <style ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required