JavaScript
  Home arrow JavaScript arrow Page 4 - Developing the Client-Side Code for Server...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Developing the Client-Side Code for Server-Side Data Validation with AJAX
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2006-07-18

    Table of Contents:
  • Developing the Client-Side Code for Server-Side Data Validation with AJAX
  • Triggering HTTP requests in the background: meet the world of requester objects
  • Processing server responses: defining the “displayErrorMessage()” function
  • Controlling the flow of data validation: defining the “initializeForm()” function
  • Integrating the client-side application layer: listing all of the JavaScript functions

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Developing the Client-Side Code for Server-Side Data Validation with AJAX - Controlling the flow of data validation: defining the “initializeForm()” function


    (Page 4 of 5 )

    It's quite possible that now you’re wondering how the flow of data validation is controlled inside the application. Well, in this case, I decided to trigger an HTTP request to the server each time the user moves the focus out of a particular form field by using the “onblur” event handler, but this behavior can be improved or even entirely changed to provide the application with better usability and accessibility.

    Having said that, below I listed the source code of the “inititializeForm()” function, which looks like this:

      function initializeForm(){
        document.getElementsByTagName('form')[0].elements
    [3].disabled=true;
        var elems=document.getElementsByTagName('form')[0].elements;
        if(!elems){return};
        for(var i=0;i<elems.length;i++){
            // check for 'required' attribute
            if(elems[i].getAttribute('required')){
                elems[i].onblur=function(){
                    // validate current field
                    sendHttpRequest('validator1.php?
    field='+this.getAttribute('name')
    +'&value='+this.value+'&method='+this.getAttribute('required')
    +'&message='+this.getAttribute
    ('title'),'displayErrorMessage',false);
                }
            }
        }
      }

    As you can see, the above function doesn’t bear much discussion, so I'll explain quickly what it does. First, it disables the submitting button of the online form, and next attaches the “sendHttpRequest()” function to all the input boxes that have a “required” attribute. Undoubtedly, this part of the function is the most important one, and should be appropriately evaluated, in case that you may want to use another event handler.

    Okay, at this stage you hopefully learned how the flow of input validation is entirely controlled by the function that you saw before. But I’m pretty sure that you want to see the complete list of JavaScript functions that I defined earlier. To examine the full source code that corresponds to the client-side layer of this AJAX application, all you have to do is jump into the next section and keep reading.

    More JavaScript Articles
    More By Alejandro Gervasio


       · In this second article of the series, all the JavaScript functions that compose the...
       · where to find the third part of Server-Side Data Validation with AJAX? I cann't find...
       · Thank you for your interest on my AJAX article. You can read the last part...
     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT