Home arrow JavaScript arrow Page 3 - A Basic Approach to Server-side Data Validation with AJAX

A Basic Approach to Server-side Data Validation with AJAX

Would you like to learn how to validate user-supplied data using JavaScript, but without the risks? This article will show you how to handle it in a way that takes advantage of JavaScript's pluses, but adds a level of safety, thanks to AJAX. It is the first of three parts.

Author Info:
By: Alejandro Gervasio
Rating: 4 stars4 stars4 stars4 stars4 stars / 17
July 11, 2006
  1. · A Basic Approach to Server-side Data Validation with AJAX
  2. · A picture is worth a thousand words: defining the look and feel of the application
  3. · Building a basic sample form: defining the front-end of the AJAX-based form checking system
  4. · Spicing up the sample form: defining a few CSS declarations
  5. · Putting the pieces together: listing the full (X)HTML markup and CSS styles of the AJAX application

print this article

A Basic Approach to Server-side Data Validation with AJAX - Building a basic sample form: defining the front-end of the AJAX-based form checking system
(Page 3 of 5 )

In this particular case, defining the front-end of this AJAX-driven application for checking online forms is a very simple process. It will be limited to coding a simple web form, which will be comprised of a few text boxes to allow a user to enter typical data, such as the user's First name, Last Name, and finally an email address.

Based on the above description, here is the respective (X)HTML markup code that constructs the sample form in question:

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/
    <title>AJAX-BASED FORM VALIDATOR</title>
    <div><p>AJAX-BASED FORM VALIDATOR</p></div>
    <div id="formcontainer">
      <form method="post" action="nextpage.php">
        <p>First Name <input name="fname" type="text" required="Empty" class="inputbox" title="Enter your First Name (at least 8 characters)" /></p>
        <p>Last Name <input name="lname" type="text" required="Empty" class="inputbox" title="Enter your Last Name (at least 8 characters)" /></p>
        <p>Email <input name="email" type="text" required="EmailWin" class="inputbox" title="Enter a valid email address" /></p>
        <p><input type="submit" value="Send Data" class="formbutton" /></p>

As you can see, the (X)HTML markup code listed above renders a simple online form, which is made up of three text fields: First Name, Last Name and Email respectively. Additionally, I added a "required" attribute to each field, indicating that these boxes must be filled. However don't you worry about the values assigned to this attribute, since I'll explain its correct meaning when I cover the development of the corresponding PHP validation routines later on.

So far, I created the basic structure of the sample online form, which will be used for testing the capabilities of this AJAX-based application, handy for validating forms. Now, the next logical step consists of tying the corresponding CSS styles to each element of the aforementioned form, to make it look a little more appealing and polished.

With reference to spicing up the corresponding sample form, I recommend you  read the next section so you can see how this will be done. Don't worry, I'll be there waiting for you.

blog comments powered by Disqus

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials