Home arrow HTML arrow Page 4 - Sending Email with AJAX: Building a Small Application
HTML

Sending Email with AJAX: Building a Small Application


AJAX has become ubiquitous, thanks to the fact that it gives web developers the ability to create applications that make http requests without reloading the page on which the application is running. It is also extremely versatile and powerful. This article, the first in a series, will start you on the way to creating an AJAX-based email application.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 42
January 17, 2006
TABLE OF CONTENTS:
  1. · Sending Email with AJAX: Building a Small Application
  2. · Getting started: developing the application’s user interface
  3. · Spicing things up: writing the CSS rules for the AJAX email application
  4. · Working with building blocks: defining the (X)HTML markup for the email application

print this article
SEARCH DEVARTICLES

Sending Email with AJAX: Building a Small Application - Working with building blocks: defining the (X)HTML markup for the email application
(Page 4 of 4 )

Since I’ve already defined the CSS styles responsible for achieving the visual appearance of the user interface that integrates the application, the only remaining step that I need to complete this project is to write the (X)HTML markup for the corresponding web page, so both document structure and visual presentation are hooked up to each other. Having said that, here is the underlying markup, which completes the required pieces for rendering the user interface. Take a look:

<div id="container">
<div id="contsection">
<h1>CONTACT LIST</h1>
<form>
<input name="add" type="button" value="Add Contact" class="mailbutton" title="Add new contact" />
</form>
</div>
<div id="mailsection">
<h1>STATUS: COMPOSING NEW MESSAGE</h1>
<form>
<input name="subject" type="text" value="SUBJECT: "
class="mailfield" title="Enter message's subject" />
<input name="to" type="text" value="TO: " class="mailfield"
title="Enter recipient's email address" />
<input name="cc" type="text" value="CC: " class="mailfield"
title="Enter email address for carbon copy" />
<input name="bcc" type="text" value="BCC: " class="mailfield"
title="Enter email address for blind carbon copy" />
<textarea name="message" title="Type your message
here" /></textarea>
<input name="send" type="button" value="Send Message"
class="mailbutton" title="Send Message" />
<input name="clear" type="reset" value="Clear Message"
class="mailbutton" title="Clear Message" />
<input name="contact" type="button" value="Display Contacts"
class="mailbutton" title="Display Contact List" />
</form>
</div>
</div>

As you’ll probably agree, the above (X)HTML markup is fairly simple, but worth spending a few minutes examining in detail, since all the further behaviors –- added by the inclusion of JavaScript code -- will be implemented on this web page structure.

As illustrated above, the markup is comprised of the three containing DIVS that I mentioned previously, named “container”, “contsection” and “mailsection” respectively. Additionally, the right-positioned DIV wraps up the appropriate form (handy for sending out email messages) and the set of control buttons, which are responsible for performing the tasks I described before. Now, coming to the left-placed DIV, you can see that it only houses a <h1> header and the “Add Contact” labeled button, which probably makes you wonder: where’s the list of contacts I saw in the previous screenshot? Right, there’s still no contact list because it will be added dynamically via JavaScript and the DOM, so don’t worry about this issue for the moment.

Now that you know what the (X)HTML markup of the email application looks like, let’s take a final step and put it together with the CSS styles that you saw earlier, so you can have a clear idea of how the complete presentational layer is implemented. Here’s the full source code for the user interface, which will be used by the AJAX-driven email program:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>AJAX-DRIVEN MAIL CLIENT</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-
8859-1">
<style type="text/css">
body {
            margin: 0;
            padding: 0;
}
h1 {
            font: bold 16px Arial, Helvetica, sans-serif;
            margin: 5px;
}
a:link,a:visited {
            display: block;
            width: 120px;
            padding: 2px 0 2px 5px;
            font: bold 12px Verdana, Arial, Helvetica, sans-
serif;
            color: #00f;
            text-decoration: none;
            border: 1px solid #cc3;
}
a:hover {
            color: #f33;
            background: #fff;
            border: 1px solid #000;
}
form {
            display: inline;
}
textarea {
            width: 575px;
            height: 380px;
            margin-left: 5px;
            background: #ffc;
            border: 1px solid #000;
}
#container {
            width: 800px;
            height: 572px;
            padding: 5px;
            margin-left: auto;
            margin-right: auto;
            background: #cc9;
            border: 1px solid #000;
}
#mailsection{
            float: left;
            width: 590px;
            height: 570px;
            margin-left: 5px;
            background: #cc3;
            border: 1px solid #000;
}
#contsection {
            float: left;
            width: 200px;
            height: 570px;
            background: #cc3;
            border: 1px solid #000;
            overflow: auto;
}
.mailfield {
            width: 575px;
            height: 20px;
            margin: 0 0 5px 5px;
            border: 1px solid #000;
            background: #ffc;
            font: bold 11px Verdana, Arial, Helvetica, sans-
serif;
            color: #000;
}
.mailbutton {
            width: 120px;
            height: 25px;
            margin-left: 5px;
            font: bold 11px Verdana, Arial, Helvetica, sans-
serif;
            color: #000;
}
.contfield {
            width: 185px;
            height: 20px;
            margin: 0 0px 5px 5px;
            border: 1px solid #000;
            background: #ffc;
            font: bold 11px Verdana, Arial, Helvetica, sans-
serif;
            color: #000;
}
</style>
</head>
<body>
<div id="container">
<div id="contsection">
<h1>CONTACT LIST</h1>
<form>
<input name="add" type="button" value="Add Contact"
class="mailbutton" title="Add new contact" />
</form>
</div>
<div id="mailsection">
<h1>STATUS: COMPOSING NEW MESSAGE</h1>
<form>
<input name="subject" type="text" value="SUBJECT: "
class="mailfield" title="Enter message's subject" />
<input name="to" type="text" value="TO: " class="mailfield"
title="Enter recipient's email address" />
<input name="cc" type="text" value="CC: " class="mailfield"
title="Enter email address for carbon copy" />
<input name="bcc" type="text" value="BCC: " class="mailfield"
title="Enter email address for blind carbon copy" />
<textarea name="message" title="Type your message
here" /></textarea>
<input name="send" type="button" value="Send Message"
class="mailbutton" title="Send Message" />
<input name="clear" type="reset" value="Clear Message"
class="mailbutton" title="Clear Message" />
<input name="contact" type="button" value="Display Contacts"
class="mailbutton" title="Display Contact List" />
</form>
</div>
</div>
</body>
</html>

Here I’ve provided you with the complete source code that renders the user interface of the AJAX-based email application. However, if you don’t feel inclined to wait for the upcoming articles of the series, you can download the full code of the AJAX email program here or at the beginning of this article.

Bottom line

We’re done for the moment. However this is only a brief pause, since I’ve just outlined the guidelines for how the AJAX-based email application will work. What’s next though? In the next tutorial, I’ll be coding the corresponding behavior layer, including the full set of JavaScript functions that interact with the server-side scripts and add interactivity to each of the user controls I discussed earlier. So, don’t ever think about missing the next part!


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.

blog comments powered by Disqus
HTML ARTICLES

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

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 
Support 

Developer Shed Affiliates

 




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