O'Reilly logo

jQuery Mobile Cookbook by Chetan K Jain

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

Validating forms

Validating a form before it is submitted to the server saves bandwidth and time as errors can be trapped at the client side itself. A server request can thus be avoided. In a jQuery Mobile application, forms can be validated using JavaScript. This recipe shows you how to validate the entries made in a Blog Comments Form .

Getting ready

Copy the full code of this recipe from the code/05/validate-form sources folder. This code can be launched using the URL http://localhost:8080/05/validate-form/main.html.

How to do it...

  1. In main.html, add the following code to create a form:
    <form id='commentform' action='#' method='post'> <div data-role='fieldcontain'> <label for='username'>Name</label> <input id='username' name='username' type='text' ...

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