HTML
  Home arrow HTML arrow Page 5 - Sending Email with AJAX: Developing the Cl...
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  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
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? 
HTML

Sending Email with AJAX: Developing the Client-Side Application Layer
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 10
    2006-01-24

    Table of Contents:
  • Sending Email with AJAX: Developing the Client-Side Application Layer
  • Sending email with AJAX: defining the “email sender” module
  • Displaying contacts: defining the “contact listing” module
  • Adding new contacts: defining the “contact insertion” module
  • Initializing the AJAX email application: defining the “initializeEmailClient()” function

  • 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


    Sending Email with AJAX: Developing the Client-Side Application Layer - Initializing the AJAX email application: defining the “initializeEmailClient()” function


    (Page 5 of 5 )

    As you’ve seen before, each control button included within the application’s user interface triggers a specific process, either for fetching files from the server or for executing tasks on the client. For this reason, I need to define the “initializeEmailClient()” function, which precisely assigns “onclick” event handlers to those buttons and ties them to the respective JavaScript functions. Take a look at this function’s signature:

    function intitializeEmailClient(){
        if(document.getElementById&&document.
    getElementsByTagName&&document.createElement){
            var sendbtn=document.getElementsByTagName('form')
    [1].elements['send'];
            if(!sendbtn){return};
            // assign 'onlick' event handler to 'send' button
            sendbtn.onclick=function(){
                // display message
                document.getElementsByTagName('h1')
    [1].firstChild.data='STATUS: SENDING MESSAGE...';
                // send email request
                sendEmailRequest();     
            }
            var clearbtn=document.getElementsByTagName('form')
    [1].elements['clear'];
            if(!clearbtn){return};
            // assign 'onlick' event handler to 'clear message' button
            clearbtn.onclick=function(){document.getElementsByTagName
    ('h1')[1].firstChild.data='STATUS: COMPOSING NEW MESSAGE'};
            var contactbtn=document.getElementsByTagName('form')
    [1].elements['contact'];
            if(!contactbtn){return};
            // assign 'onlick' event handler to 'contact' button
            contactbtn.onclick=getContactList;
            var addbtn=document.getElementsByTagName('form')
    [0].elements['add'];
            // assign 'onlick' event handler to 'add Contact' button
            addbtn.onclick=addContact;                      
            // display contact list
            getContactList();
        }
    }

    Briefly, the above function adds the appropriate behaviors to each control button, so the user interface becomes completely functional now. In addition, since this function is called after loading the web document, the contact list is retrieved and displayed in turn by invoking the “getContactList()” function.

    Of course, the script wouldn’t be complete without instantiating the respective requester objects that fetch the PHP and XML files from the server, so they’re created below:

    // instantiate email XMLHttpRequest object
    var emailXMLHttpObj=getXMLHttpRequestObject();
    // instantiate contact XMLHttpRequest object
    var contactXMLHttpObj=getXMLHttpRequestObject();
    // instantiate insert XMLHttpRequestObject
    var insertXMLHttpObj=getXMLHttpRequestObject();

    And finally, the “initializeEmailClient()” function is called up after the web page has been loaded, like this:

    window.onload=intitializeEmailClient;

    Well, at this stage I’ve provided you with all the JavaScript functions that compose the client-side application layer of this AJAX-based email program. I hope you enjoy testing and tweaking the code, so it can work specifically for you. Have a good time!

    Bottom line

    In this tutorial, hopefully you’ve learned how the JavaScript building blocks of the AJAX email program fit each other. Aside from using regular functions, the overall development process has been instructive for illustrating a simple approach for working with multiple requester objects across the sample application.

    However, as you know, the program isn’t complete yet. Over the last part of the series, I’ll turn attention to the server-side programming, by coding the PHP snippet that collects data from the client and actually sends the appropriate email messages. See you in the last article!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · The second article of this series goes through the development of the required...
     

    HTML ARTICLES

    - Tabular Database Forms with HTML
    - Using the Find Functions for HTML Database F...
    - Sorting for Database Forms with HTML
    - Edit and Other Database Form Functions with ...
    - More Database Form Functions with HTML
    - Database Form Functions with HTML
    - Using the HTML Table Element as a Recordset
    - Building Single Row Database Forms with HTML
    - Introduction to Database Forms with HTML
    - Another Look at Animation of Geographical Ma...
    - Animation of Geographical Map Regions
    - Changing and Moving Pictures with CSS
    - Clickable Geographical Map Regions
    - Gradient Creation with the HR Element
    - Text on HTML Images: Do it Yourself







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway