<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tricklin &#187; JavaScript</title>
	<atom:link href="http://www.patmullin.com/weblog/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.patmullin.com/weblog</link>
	<description></description>
	<lastBuildDate>Fri, 24 Sep 2010 14:14:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Sortable List Example With Scriptaculous and PHP/mySQL</title>
		<link>http://www.patmullin.com/weblog/2007/01/05/sortable-list-example-with-scriptaculous-and-phpmysql/</link>
		<comments>http://www.patmullin.com/weblog/2007/01/05/sortable-list-example-with-scriptaculous-and-phpmysql/#comments</comments>
		<pubDate>Thu, 04 Jan 2007 19:26:23 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.patmullin.com/weblog/?p=74</guid>
		<description><![CDATA[After spending a considerable amount of time looking for a decent example of "how to store the newly sorted order of a list after dragging and dropping", I realized that there isn't a whole lot of examples and documentation out there. I've decided that it's my turn to try and come up with a full [...]]]></description>
			<content:encoded><![CDATA[<p>After spending a considerable amount of time looking for
a decent example of "how to store the newly sorted order of
a list after dragging and dropping", I realized that there
isn't a whole lot of examples and documentation out there. 
I've decided that it's my turn to try and come up with a
full blown, easy to understand example using XHTML,
Javascript, PHP, and mySQL.</p>
<p>First off, you'll need both the <a
href="http://script.aculo.us/downloads"
target="_blank">scriptaculous</a> and <a
href="http://script.aculo.us/downloads"
target="_blank">prototype</a> javascript libraries (both
available from <a href="http://script.aculo.us"
target="_blank">script.aulo.us</a>).  Once you've downloaded
these files, you'll need to reference them in the
<code>head</code> of your file:</p>
<p><span id="more-74"></span></p>
<pre class="brush: html">
&lt;script type=&quot;text/javascript&quot;
src=&quot;scripts/prototype.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;scripts/scriptaculous.js&quot;&gt;&lt;/script&gt;
</pre>
<p>Then, in your html file, make your list:</p>
<pre class="brush: html">
&lt;ul id=&quot;items_list&quot;&gt;
	&lt;li id=&quot;item_1&quot;&gt;Item 1&lt;/li&gt;
	&lt;li id=&quot;item_2&quot;&gt;Item 2&lt;/li&gt;
	&lt;li id=&quot;item_3&quot;&gt;Item 3&lt;/li&gt;
&lt;li id=&quot;item_4&quot;&gt;Item 4&lt;/li&gt;
</pre>
<p>Note that the <code>ul</code> and each <code>li</code>
have unique <code>id</code>s.  It is also important to note
that the <code>id</code>s of the list items must have "_#"
at the end (this number must be unique).</p>
<p>Next, add this after the list (because of IE):</p>
<pre class="brush: html">
&lt;script type=&quot;text/javascript&quot;
language=&quot;javascript&quot;&gt;
Sortable.create(&quot;items_list&quot;,{dropOnEmpty:true,con
straint:false});
&lt;/script&gt;
</pre>
<h3>Cool!  It works!  But...</h3>
<p>Now that you've done this, go ahead and check it out. 
Cool...  You can now sort your list by dragging and
dropping!  This is all fine and dandy, but how do I actually
store this new order in my database?</p>
<p>It's pretty simple actually.  In comes "serialize", to
make life easy.  This little gem creates a string containing
information on of the current state of the list being
sorted.  How do you use it?</p>
<pre class="brush: html">
var listorder = Sortable.serialize(&#039;items_list&#039;);
</pre>
<p>Let's say that you've sorted your list as follows:
</ul>
<ul>
<li>item 3</li>
<li>item 2</li>
<li>item 1</li>
<li>item 4</li>
</ul>
<p>When invoked, the variable <code>listorder</code> would
return as
"<code>items_list[]=3&items_list[]=2&items_list[]=1&items_li
st[]=4</code>".  And this is what you need to update your
database.  Notice, the values returned are associated to
whatever is after the underscore (<code>_</code>) in the
<code>id</code> of the list item.</p>
<p>Now that you have this information, you can easily update
your database with a simple <abbr title="Asynchronous
Javascript And XML">AJAX</abbr> call pointing to your php
file ('save_items_order.php' in this case):</p>
<pre class="brush: javascript">
function saveOrder() {
	listorder = Sortable.serialize(&#039;items_list&#039;);
	var url = &#039;save_items_order.php&#039;;
	var pars = listorder
		+ &#039;&amp;rnd=&#039;
		+ new Date().getTime();
	var myAjax = new Ajax.Request(
		url,
		{
			method: &#039;post&#039;,
			postBody: pars,
			onComplete:  showList
		});
}
</pre>
<p>Finally, the PHP/mySQL piece:</p>
<pre class="brush: php">
if($_POST) {
  $items = $_POST[&#039;items_list&#039;];
  $i = 1; # will represent the actual order (starting at 1).
  foreach($items as $itemid) {
    $query = &quot;
      UPDATE items_table SET order_col = $i WHERE id_col =
$itemid
    &quot;;
    mysql_query($query);
    $i++;  # add 1 to the current value of i (the next order
in the list).
  }
}
</pre>
<p>There you have it.  An example of how to sort a list, and
then store the new order in your database.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patmullin.com/weblog/2007/01/05/sortable-list-example-with-scriptaculous-and-phpmysql/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Debug JavaScript in IE</title>
		<link>http://www.patmullin.com/weblog/2006/08/01/debug-javascript-in-ie/</link>
		<comments>http://www.patmullin.com/weblog/2006/08/01/debug-javascript-in-ie/#comments</comments>
		<pubDate>Tue, 01 Aug 2006 14:59:16 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.patmullin.com/weblog/?p=61</guid>
		<description><![CDATA[I ALWAYS use Firefox to debug my JavaScript code. There are plenty of plugins that allow for you to easily debug problems in your code. But what about when your code runs perfectly fine in Firefox, but not in IE? How do you debug your JavaScript code in IE? I've finally found the answer: Step [...]]]></description>
			<content:encoded><![CDATA[<p>I <strong>ALWAYS</strong> use Firefox to debug my
JavaScript code.  There are plenty of plugins that allow for
you to easily debug problems in your code.  But what about
when your code runs perfectly fine in Firefox, but not in
IE? How do you debug your JavaScript code in IE?  I've
finally found the answer:</p>
<h3>Step 1 - Enable script debugging.</h3>
<p>Now the process for doing this is <em>obvious</em>.  Go
to "Tools -> Internet Options... -> Advanced".  From here,
find "Disable Script Debugging (Internet Explorer)", and
"Disable Script Debugging (Other)".  Now, follow me here... 
To <strong>enable</strong> script debugging, you need to
<strong>uncheck</strong> these boxes.  Very intuitive, I
know.  Once you've unchecked these two boxes, click
"OK".</p>
<p><span id="more-61"></span></p>
<h3>Step 2 - Open up your debugger.</h3>
<p>To access your debugger, run your script (i.e. reload
your html page, and trigger the JavaScript).  A new pop-up
message should appear.<br />
<br />
<img src="http://www.patmullin.com/images/runtime_error.png"
alt="IE runtime error" /><br />
<br />
Click <u>Y</u>es.  Doing so, will bring up another
window.<br />
<br />
<img src="http://www.patmullin.com/images/jit_debugging.png"
alt="Just-In-Time Debugging" /><br />
<br />
There are three applications available for script debugging:
"Visual Studio.Net", "Microsoft Script Debugger" and
"Microsoft Script Editor".  You may be limited in your
choices, however (see image).  Choose the debugger from the
list, and click <u>Y</u>es.  This will bring up the
debugger, which will most likely take you to the line of
code that is causing the problems.<br />
<br />
<img src="http://www.patmullin.com/images/debugger.png"
alt="Debugger tool" /><br />
<br />
There you have it.  A way to debug JavaScript in IE.</p>
<h3>Hints and Other Articles</h3>
<ul>
<li>Type "javascript:debugger;" in the address and hit enter
to open up your debugger.</li>
<li>Type "if(typeof(res)=="object") debugger;" in your code
to launch the debugger at a break point.</li>
<li><a
href="http://blogs.msdn.com/ie/archive/2004/10/26/247912.asp
x">Scripting Debugging in Internet Explorer</a></li>
<li><a
href="http://weblogs.asp.net/mschwarz/archive/2005/04/19/403
327.aspx">Debug Internet Explorer Javascript</a></li>
<li><a
href="http://www.jonathanboutelle.com/mt/archives/2006/01/ho
wto_debug_jav.html">HOW-TO: Debug JavaScript in Internet
Explorer</a></li>
</ul>
<p>Hopefully this helps take away some of the pain that is
Internet Explorer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patmullin.com/weblog/2006/08/01/debug-javascript-in-ie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fiddling With TiddlyWiki</title>
		<link>http://www.patmullin.com/weblog/2006/05/10/fiddling-with-tiddlywiki/</link>
		<comments>http://www.patmullin.com/weblog/2006/05/10/fiddling-with-tiddlywiki/#comments</comments>
		<pubDate>Tue, 09 May 2006 22:00:45 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.patmullin.com/weblog/?p=52</guid>
		<description><![CDATA[*** UPDATE - 5/10 It has come to my attention that my co-worker actually uses a modified version of TiddlyWiki called GTDTiddlyWiki. GTD Tiddly Wiki is a GettingThingsDone adaptation by NathanBowers of JeremyRuston's Open Source TiddlyWiki. The purpose of GTD Tiddly Wiki is to give users a single repository for their GTD lists and support [...]]]></description>
			<content:encoded><![CDATA[<p>*** </p>
<p><strong>UPDATE - 5/10</strong><br />
It has come to my attention that my co-worker actually uses
a modified version of <a
href="http://www.tiddlywiki.com">TiddlyWiki</a> called <a
href="http://shared.snapgrid.com/">GTDTiddlyWiki</a>. </p>
<blockquote><p>GTD Tiddly Wiki is a GettingThingsDone
adaptation by NathanBowers of JeremyRuston's Open Source
TiddlyWiki. The purpose of GTD Tiddly Wiki is to give users
a single repository for their GTD lists and support
materials so they can create/edit lists, and then print
directly to 3x5 cards for use with the HipsterPDA.  -- <a
href="http://shared.snapgrid.com/">shared.snapgrid.com</a></
p></blockquote>
<p>***</p>
<p><a href="http://www.patmullin.com/empty.html"><img
src="http://www.patmullin.com/images/tiddlywiki.png"
alt="tiddlywiki" class="floatleft" /></a>I noticed a
co-worker always entering things into some HTML interface
every day.  Finally, I had to find out just what this tool
was.  It turns out, that this tool was what he uses to
organize his day.  He uses it as his personal To Do list.  I
know that just knowing this, won't amaze you.  The cool
thing about this tool, is that all that is involved is a
single '.html' file.  That's right, he manages his personal
life using a single '.html' file.</p>
<h3>What?  A Single HTML File?</h3>
<p>A guy named Jeremy Ruston developed a cool tool called
"<a href="http://www.tiddlywiki.com">TiddlyWiki</a>", and
it's made and functions completely off of JavaScript and
HTML contained in one '.html' file.  All you have to do is
go to <a href="http://www.tiddlywiki.com">TiddlyWiki</a>,
and download this '.html' file and you can get started. 
Once opened in a browser (preferably Firefox), you can add
to it whatever you please.  Take a <a
href="http://www.patmullin.com/empty.html">look at what I
was able to do</a> in about 2 minutes.</p>
<p><span id="more-52"></span></p>
<blockquote><p>
Out of the box, TiddlyWiki offers:</p>
<ul>
<li>Browsable with the vast majority of modern desktop
browsers on Windows, Macintosh and Linux and including the
Nokia770</li>
<li>Ability to SaveChanges on FireFox under Windows or OS X,
InternetExplorer under Windows and Safari and Camino under
OS X</li>
<li>Rich formatting including MonospacedText,
ExtendedFormatting, NonWikiWordLinks, WikiWordEscape,
PrettyLinks, SubHeadings, BulletPoints,
NumberedBulletPoints, Tables, BlockQuotes, HorizontalRules
and the ability to use a CustomCssClass.</li>
<li>Various InterfaceOptions, including the ability to
GenerateAnRssFeed, SaveBackups and AutoSave</li>
<li>KeyboardShortcuts so you can finish editing a tiddler
with Control-Enter or abandon it with Escape</li>
<li>InlineHTML</li>
<li>...EmbeddedImages:</li>
<li>Macros providing rich interactive features, including
Sparklines and Gradients</li>
<li>a flexible OpenSourceLicense</li>
<li>a liquid CSS layout that can be customised with a
CustomStyleSheet</li>
<li>Extensive StartupParameters to control the behaviour of
TiddlyWiki through specially crafted URLs</li>
</ul>
<p>The Community around TiddlyWiki has extended this basic
functionality with a wide range of Plugins and
TiddlyWikiAdaptations.                   --  Jeremy Ruston,
<a href="http://www.tiddlywiki.com">www.tiddlywiki.com</a>
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.patmullin.com/weblog/2006/05/10/fiddling-with-tiddlywiki/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>getAttribute(&#8217;style&#8217;), setAttribute(&#8217;style&#8217;) &amp; IE Don&#8217;t Mix</title>
		<link>http://www.patmullin.com/weblog/2006/04/06/getattributestyle-setattributestyle-ie-dont-mix/</link>
		<comments>http://www.patmullin.com/weblog/2006/04/06/getattributestyle-setattributestyle-ie-dont-mix/#comments</comments>
		<pubDate>Thu, 06 Apr 2006 15:46:44 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.patmullin.com/weblog/?p=48</guid>
		<description><![CDATA[I was recently working on an idea I had to be able to increase and decrease the size of a div using a little JavaScript. I figured the best way to do this was by using DOM objects and methods. The specific nodes I was going to use were getAttribute (to grab the height of [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently working on an idea I had to be able to
increase and decrease the size of a <code>div</code> using a
little JavaScript.  I figured the best way to do this was by
using <a
href="http://www.howtocreate.co.uk/tutorials/javascript/doms
tructure" title="Click here to learn more about DOM objects
and methods">DOM objects and methods</a>.  The specific
nodes I was going to use were <code>getAttribute</code> (to
grab the height of the <code>div</code>) and
<code>setAttribute</code> (to set the new height of the
<code>div</code>).  Guess what?  It worked great in Firefox,
while returning an error in IE.  Surprise, surprise!</p>
<h3>getAttribute('style') - The Problem</h3>
<p>Using
<code>document.getElementById('[<em>id_of_element</em>]').ge
tAttribute('style')</code> returns a string in Firefox (ex.
"<code>height: 200px</code>"), yet in IE it merely returns
an object.   Which means additional code to get this into a
string.</p>
<h3>getAttribute('style') - The Solution</h3>
<p class="blockcode">
var el =
document.getElementById('[<em>id_of_element</em>]');<br />
var styleattribute = el.getAttribute('style');<br />
if (typeof styleattribute == 'string') {  // what Firefox
returns<br />
&nbsp;&nbsp;&nbsp;&nbsp;...<br />
} else if (typeof styleattribute == 'object') {   // what IE
returns<br />
&nbsp;&nbsp;&nbsp;&nbsp;styleattribute = styleattribute
.cssText;<br />
}
</p>
<p>One thing to note here, is that
<code>styleattribute.cssText</code> returns ALL CAPS. 
Meaning: if the element contains
<code>style="height:200px;"</code>,
<code>styleattribute.cssText</code> will return
<code>HEIGHT: 200px</code>.</p>
<h3>setAttribute('style') - The Problem</h3>
<p>This just flat out doesn't work in IE.  <a
href="http://www.quirksmode.org/bugreports/archives/2005/03/
setAttribute_does_not_work_in_IE_when_used_with_th.html">See
entry at quirksmode.org</a>.</p>
<h3>setAttribute('style') - The Solution</h3>
<p class="blockcode">
document.getElementById('[<em>id_of_element</em>]').style.he
ight = 250;
</p>
<p>So, there you have it.  Yet another reason to hate IE.  
At least there's a solution to the problem, albeit a rather
annoying one.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patmullin.com/weblog/2006/04/06/getattributestyle-setattributestyle-ie-dont-mix/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Alternating Row Colors Using Only JavaScript</title>
		<link>http://www.patmullin.com/weblog/2006/04/05/alternating-row-colors-using-only-javascript/</link>
		<comments>http://www.patmullin.com/weblog/2006/04/05/alternating-row-colors-using-only-javascript/#comments</comments>
		<pubDate>Wed, 05 Apr 2006 15:36:49 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.patmullin.com/weblog/?p=47</guid>
		<description><![CDATA[Below is a JavaScript that will make alternating the row colors of a table extremely simple. The beauty of it is that the script is only 16 lines long! function alternateRowColor(tableid,lightclass,darkclass,overclass) { &#160;&#160;&#160;&#160;var tableid = document.getElementById(tableid); &#160;&#160;&#160;&#160;var rows = tableid.tBodies[0].rows; &#160;&#160;&#160;&#160;for(var ii = 0; ii < rows.length; ii++) { &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;var row = rows[ii]; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if(ii % [...]]]></description>
			<content:encoded><![CDATA[<p>Below is a JavaScript that will make alternating the row
colors of a table extremely simple.  The beauty of it is
that the script is only 16 lines long!</p>
<p class="blockcode">
function
alternateRowColor(tableid,lightclass,darkclass,overclass)
{<br />
	&nbsp;&nbsp;&nbsp;&nbsp;var tableid =
document.getElementById(tableid);<br />
	&nbsp;&nbsp;&nbsp;&nbsp;var rows =
tableid.tBodies[0].rows;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;for(var ii = 0; ii < rows.length;
ii++) {<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var row =
rows[ii];<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(ii % 2)
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;row.className =
lightclass;	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;row.onmouseover = function ()
{overRow(this.id,overclass);};<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;row.onmouseout = function ()
{overRow(this.id,lightclass);};<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else
{<br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;row.className = darkclass;<br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;row.onmouseover = function ()
{overRow(this.id,overclass);};<br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;row.onmouseout = function ()
{overRow(this.id,darkclass);};<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
	&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}
</p>
<p>I've added a nice little row highlighting function to the
mouseover and mouseout events called
<code><strong>overRow()</strong></code>.  This function only
adds 3 lines of code:</p>
<p class="blockcode">
function overRow(rowid, classname) {<br />
	&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById(rowid).clas
sName = classname;<br />
}
</p>
<p>The last thing to do is make sure that the
<code><strong>alternateRowColor()</strong></code> function
gets invoked every time the page loads.  Instead of having
to place this in the <code>body</code> tag of all pages, all
that is needed is one line of code added to the same script
that will automatically run the function each time a page
loads:</p>
<p class="blockcode">
window.onload=function(){
alternateRowColor('alternateRows','light','dark','over');}
</p>
<p>That's all there is to it.  <a
href="http://www.patmullin.com/alternating_row_color_js.html
" title="Click here to see a demo of the alternating row
color javascript.">See it in action</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patmullin.com/weblog/2006/04/05/alternating-row-colors-using-only-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple AJAX Example Using ColdFusion</title>
		<link>http://www.patmullin.com/weblog/2006/03/03/simple-ajax-example-using-coldfusion/</link>
		<comments>http://www.patmullin.com/weblog/2006/03/03/simple-ajax-example-using-coldfusion/#comments</comments>
		<pubDate>Thu, 02 Mar 2006 22:54:09 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.patmullin.com/weblog/?p=46</guid>
		<description><![CDATA[As I mentioned in my previous post, I planned on creating a "tutorial that will walk you through a real world working example of AJAX using ColdFusion and a simple MS Access Database." Well, here it is: In order to represent a working example of AJAX, there are a few things we're going to need. [...]]]></description>
			<content:encoded><![CDATA[<p>As I mentioned in my previous <a
href="http://weblog.patmullin.com/?p=46">post</a>, I planned
on creating a "tutorial that will walk you through a real
world working example of <abbr title="Asynchronous
JavaScript and XML">AJAX</abbr> using ColdFusion and a
simple MS Access Database."  Well, here it is:</p>
<p>In order to represent a <a
href="http://www.patmullin.com/view_add_employees.html"
title="Click here to see the AJAX demo live.">working
example</a> of <abbr title="Asynchronous JavaScript and
XML">AJAX</abbr>, there are a few things we're going to
need.</p>
<ul>
<li>database</li>
<li>HTML file</li>
<li>JavaScript (located within the HTML file in this
example)</li>
<li>ColdFusion file (note: any programming language can be
used)</li>
<li>prototype JavaScript library</li>
</ul>
<h3>The Database</h3>
<p>The database used in this example is an extremely basic
MS Access database consisting of one table that contains 6
fields:</p>
<table border="1" cellpadding="6" cellspacing="0"
width="100%">
<thead>
<tr>
<td colspan="2"><strong>Table
Name:</strong>&nbsp;&nbsp;Employee</td>
</tr>
<tr>
<td><strong>Field Name</strong></td>
<td><strong>Data Type</strong></td>
</tr>
</thead>
<tbody>
<tr class="highlight">
<td>EmpID</td>
<td>AutoNumber</td>
</tr>
<tr>
<td>FirstName</td>
<td>Text</td>
</tr>
<tr class="highlight">
<td>LastName</td>
<td>Text</td>
</tr>
<tr>
<td>JobTitle</td>
<td>Text</td>
</tr>
<tr class="highlight">
<td>Phone</td>
<td>Text</td>
</tr>
<tr>
<td>Fax</td>
<td>Text</td>
</tr>
</tbody>
</table>
<p>Now that we know what we are going to be storing, let's
take a look at the "<code>.html</code>" file.</p>
<h3>HTML File</h3>
<p>This file will consist of the form fields needed to
populate the database, along with the placeholder we will
use to show the information being stored:</p>
<pre class="brush: html">
&lt;form name=&quot;addEmployee&quot;&gt;
First Name:&lt;input type=&quot;text&quot;
name=&quot;FirstName&quot; id=&quot;FirstName&quot;
value=&quot;&quot; size=&quot;30&quot; /&gt;
&lt;br /&gt;
Last Name:&lt;input type=&quot;text&quot;
name=&quot;LastName&quot; id=&quot;LastName&quot;
value=&quot;&quot; size=&quot;30&quot; /&gt;
&lt;br /&gt;
Job Title:&lt;input type=&quot;text&quot;
name=&quot;JobTitle&quot; id=&quot;JobTitle&quot;
value=&quot;&quot; size=&quot;30&quot; /&gt;
&lt;br /&gt;
Phone:&lt;input type=&quot;text&quot; name=&quot;Phone&quot;
id=&quot;Phone&quot; value=&quot;&quot; size=&quot;12&quot;
/&gt;
&lt;br /&gt;
Fax:&lt;input type=&quot;text&quot; name=&quot;Fax&quot;
id=&quot;Fax&quot; value=&quot;&quot; size=&quot;12&quot;
/&gt;
&lt;br /&gt;
&lt;input type=&quot;button&quot; name=&quot;submit&quot;
value=&quot;save&quot;
onclick=&quot;insertEmployee();&quot;/&gt;
&lt;/form&gt;
&lt;div id=&quot;EmployeeList&quot;&gt;&lt;/div&gt; 
//placeholder div
</pre>
<p>Notice how there is no <code>method</code> or
<code>action</code> in the <code>form</code> tag?  Both of
these will be taken care of by the JavaScript.</p>
<p><span id="more-46"></span></p>
<h3>The JavaScript</h3>
<p>Once you've gotten all the form fields you need, you're
now ready to start writing the JavaScript that will handle
the <abbr title="Asynchronous JavaScript and
XML">AJAX</abbr> portion.  First, make sure you are
referencing "<a href="http://prototype.conio.net/"
title="Click here to download the latest version of
prototype.js.">prototype.js</a>" (<code>&lt;script
src="/scripts/prototype-1.4.0.js"&gt;&lt;/script&gt;</code>)
.  Now that prototype is in place, we can begin writing the
necessary code to populate the "<code>Employee</code>"
table.  Notice from the xhtml code (above) the
<code>onclick</code> event attached to the save button:
<code>onclick="insertEmployee();"</code>.  This
<code>function</code> is going to be called everytime a user
clicks the "<code>save</code>" button.  Let's take a look at
this function:</p>
<pre class="brush: javascript">
function insertEmployee() {
	// begin form variables
	var fname = $F(&#039;FirstName&#039;);
	var lname = $F(&#039;LastName&#039;);
	var jtitle = $F(&#039;JobTitle&#039;);
	var phone = $F(&#039;Phone&#039;);
	var fax = $F(&#039;Fax&#039;);
	// end form variables
	var url = &#039;employee.cfm&#039;;
	var pars = &#039;FirstName=&#039;
			   + fname
			   + &#039;&amp;LastName=&#039;
			   + lname
			   + &#039;&amp;JobTitle=&#039;
			   + jtitle
			   + &#039;&amp;Phone=&#039;
			   + phone
			   + &#039;&amp;Fax=&#039;
			   + fax
			   + &#039;&amp;Action=Insert&amp;rnd=&#039;
			   + Math.random()*99999;
	var myAjax = new Ajax.Request(
	url,
	{
	        method: &#039;post&#039;,
	        postBody: pars,
	        onComplete: listEmployees
	});
}
</pre>
<p>First of all, we're putting the values within each form
field into variables.  We'll then use these variables to
pass them to the <code>ColdFusion</code> file, which in turn
will insert these values into the database.  The next step
is to declare a variable that will contain the actual URL of
this <abbr title="ColdFusion">CF</abbr> file.  In this
example, we're calling this variable <code>url</code>, and
we're giving it the value of "<code>employee.cfm</code>". 
This value tells us that the <abbr
title="ColdFusion">CF</abbr> file is located in the same
directory as the ".html" file.  Now that we have the values
of each form field and the URL of the <abbr
title="ColdFusion">CF</abbr> file declared, we're going to
create another variable "<code>pars</code>" which will
contain all the name/value pairs that will be passed to the
<abbr title="ColdFusion">CF</abbr> file.  In the code, we've
written these name/value pairs separated by new lines, which
improves readability.  As you can see, these name/value
pairs are passed to the <abbr title="ColdFusion">CF</abbr>
file much like you'd pass them in a URL string.  For
example:</p>
<p class ="blockcode">
employee.cfm?<strong><em>FirstName=John&LastName=Doe&JobTitl
e=Accountant...</em></strong>
</p>
<p>One thing to take note of, however, is the fact that we
are passing 2 additional name/value pairs that are not part
of the form: "<code>Action=Insert</code>" and "<code>rnd=[a
random number]</code>".  The "<code>Action=Insert</code>"
will make sense when we take a closer look at the <abbr
title="ColdFusion">CF</abbr> file.  The "<code>rnd=[a random
number]</code>" is explained in detail in my <a
href="http://weblog.patmullin.com/?p=46">previous
post</a>.</p>
<p>Now that we've got a good understanding of
"<code>pars</code>" and "<code>url</code>", let's take a
look at the actual request that we'll use to send to
back-end:</p>
<pre class="brush: javascript">
    var myAjax = new Ajax.Request(
        url,
        {
            method: &#039;post&#039;,
            postBody: pars,
            onComplete: listEmployees
        });
</pre>
<p>What the above says, is that we're going to open an
<code>XMLHttpRequest</code> that will "<code>POST</code>"
the name/value pairs (<code>pars</code>) to
"<code>employee.cfm</code>".  Then, once the request is
complete, the "<code>listEmployees</code>" function will be
run.  Now that we've got the insert request taken care of,
let's take a look at what the <abbr
title="ColdFusion">CF</abbr> file is doing on the
back-end.</p>
<h3>The ColdFusion File - "employee.cfm"</h3>
<p>We know that we want to populate the database with the
values in the form, and we know that the <abbr
title="Asynchronous JavaScript and XML">AJAX</abbr> request
will be "<code>POST</code>ing" this information.  Since the
request is using the "<code>POST</code>" method, we know
we'll have to use the "<code>FORM</code>" variable (not
<code>URL</code>) for grabbing the parameters being sent. 
Let's take a look at the <abbr title="ColdFusion">CF</abbr>
code:</p>
<pre class="brush: html">
&lt;cfif (IsDefined(&#039;Form.Action&#039;) AND Form.Action
EQ &quot;Insert&quot;)&gt;
    &lt;cflock name=&quot;Insert&quot;
type=&quot;EXCLUSIVE&quot; timeout=&quot;30&quot;&gt;
		        &lt;cfquery name=&quot;insertemployee&quot;
Datasource=&quot;employee&quot;&gt;
			            INSERT INTO Employee (FirstName, LastName,
JobTitle, Phone, Fax)
			            VALUES (&#039;#Form.FirstName#&#039;,
&#039;#Form.LastName#&#039;, &#039;#Form.JobTitle#&#039;,
&#039;#Form.Phone#&#039;, &#039;#Form.Fax#&#039;)
		        &lt;/cfquery&gt;
    &lt;/cflock&gt;
&lt;/cfif&gt;
</pre>
<p>As you can see from the first line, this set of code will
not be run unless the "<code>Action</code>" form parameter
is defined, and that it's equal to "<code>Insert</code>". 
This is where the "<code>&amp;Action=Insert</code>"
name/value pair, added to the "<code>pars</code>" variable
in the JavaScript code, comes into play.  The next set of
code uses a standard SQL statement to insert the data that
is passed into the "<code>Employee</code>" table.  The next
set of code to get run is the query that will select
everything from the "<code>Employee</code>" table, and then
return these values in a table:</p>
<pre class="brush: html">
&lt;cfquery name=&quot;listemployees&quot;
datasource=&quot;employee&quot;&gt;
    SELECT *
    FROM Employee
    ORDER BY LastName
&lt;/cfquery&gt;
&lt;table cellpadding=&quot;4&quot;&gt;
&lt;thead&gt;
    &lt;tr&gt;
        &lt;td&gt;&lt;b&gt;Last Name&lt;/b&gt;&lt;/td&gt;
        &lt;td&gt;&lt;b&gt;First Name&lt;/b&gt;&lt;/td&gt;
        &lt;td&gt;&lt;b&gt;Job Title&lt;/b&gt;&lt;/td&gt;
        &lt;td&gt;&lt;b&gt;Phone&lt;/b&gt;&lt;/td&gt;
        &lt;td&gt;&lt;b&gt;Fax&lt;/b&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;cfoutput query=&quot;listemployees&quot;&gt;
    &lt;tr id=&quot;#EmpID#&quot;&gt;
        &lt;td&gt;#LastName#&lt;/td&gt;
        &lt;td&gt;#FirstName#&lt;/td&gt;
        &lt;td&gt;#JobTitle#&lt;/td&gt;
        &lt;td&gt;#Phone#&lt;/td&gt;
        &lt;td&gt;#Fax#&lt;/td&gt;
    &lt;/tr&gt;
&lt;/cfoutput&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</pre>
<p>This table is what gets returned to the
"<code>.html</code>" page.  Remember we said that the
"<code>listEmployees</code>" function would be run when the
request is completed.  It is this function that is
responsible for making this table appear on the page:</p>
<pre class="brush: javascript">
function listEmployees(originalRequest){
    $(&#039;EmployeeList&#039;).innerHTML =
originalRequest.responseText;
    var doc = document.addEmployee;
    doc.FirstName.value = &#039;&#039;;
    doc.LastName.value = &#039;&#039;;
    doc.JobTitle.value = &#039;&#039;;
    doc.Phone.value = &#039;&#039;;
    doc.Fax.value = &#039;&#039;;
}
</pre>
<p>When this function is run, the <code>innerHTML </code>of
the "<code>EmployeeList</code>" placeholder <code>div</code>
will contain the table that was created in
"<code>employee.cfm</code>".  Also added to this function is
the clearing out of all the form fields.</p>
<p>There you have it: an example of inserting information
into a database using <abbr title="Asynchronous JavaScript
and XML">AJAX</abbr> and ColdFusion.  As you can see from
this example, you can use any programming language you
prefer.  The point of this tutorial was to explain the
step-by-step process of using <abbr title="Asynchronous
JavaScript and XML">AJAX</abbr> from front-end to back-end
to front-end again, all without refreshing the users
browser.</p>
<p>You can see this example in action by checking out a
sample <a
href="http://www.patmullin.com/view_add_employees.html">demo
</a> I've created for this tutorial.  In this demo, you will
see a little more functionality.  Feel free to view the
source of this file to see how other functions are
handled.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patmullin.com/weblog/2006/03/03/simple-ajax-example-using-coldfusion/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>My First AJAX Experience</title>
		<link>http://www.patmullin.com/weblog/2006/02/22/my-first-ajax-experience/</link>
		<comments>http://www.patmullin.com/weblog/2006/02/22/my-first-ajax-experience/#comments</comments>
		<pubDate>Tue, 21 Feb 2006 21:12:44 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.patmullin.com/weblog/?p=45</guid>
		<description><![CDATA[All in all, I'd have to say I had a very pleasant experience using AJAX for the first time. The most difficult aspect of working with AJAX, was learning how to implement it. Once I found the right documentation, it was relatively smooth sailing. Getting Started First off, you should download an AJAX library. I [...]]]></description>
			<content:encoded><![CDATA[<p>All in all, I'd have to say I had a very pleasant
experience using <abbr title="Asynchronous JavaScript and
XML">AJAX</abbr> for the first time.  The most difficult
aspect of working with <abbr title="Asynchronous JavaScript
and XML">AJAX</abbr>, was learning how to implement it. 
Once I found the right documentation, it was relatively
smooth sailing.</p>
<h3>Getting Started</h3>
<p>First off, you should download an <abbr
title="Asynchronous JavaScript and XML">AJAX</abbr> library.
 I recommend the <a
href="http://prototype.conio.net/">Prototype</a> javascript
library.   What is prototype.js anyway?</p>
<blockquote><p>Prototype is a JavaScript framework that aims
to ease development of dynamic web applications. Featuring a
unique, easy-to-use toolkit for class-driven development and
the nicest <abbr title="Asynchronous JavaScript and
XML">AJAX</abbr> library around, Prototype is quickly
becoming the codebase of choice for web application
developers everywhere.</p></blockquote>
<p>Basically, a guy named Sam Stephenson spent, I'm sure, an
inordinate amount of time writing this great javascript file
in order to make life easier on all of us.  Using this file
makes writing your <abbr title="Asynchronous JavaScript and
XML">AJAX</abbr> code much easier.  As mentioned earlier,
the hardest part about getting started was finding
documentation.  So, in order to make it simpler for you, I'm
going to include links to the documentation that I used to
get started.</p>
<ul>
<li><a
href="http://www.sergiopereira.com/articles/prototype.js.htm
l">Developer Notes for prototype.js</a> - This documentation
was exactly what I needed, and could quite possibly be the
only thing you'll need.  It contains some really great
examples in the beginning of the document, and the contains
more detailed information later on.  After reading the first
few paragraphs, I was able to get started, and then used the
rest of the document for reference (this part of the
document conveniently happens to be named "Reference for
Prototype.js") haha.</li>
<li><a
href="http://encytemedia.com/blog/articles/2006/02/08/workin
g-with-events-in-prototype">Working With Events In
Prototype</a> - How to use prototype with Keystrokes, Mouse
Clicks, Mouse Hovers, etc.</li>
<li><a
href="http://24ways.org/advent/easy-ajax-with-prototype">Eas
y Ajax with Prototype</a></li>
</ul>
<p><span id="more-45"></span></p>
<h3>What To Watch Out For</h3>
<p>Internet Explorer loves to cache everything.  This is
particularly a problem when you are using <abbr
title="Asynchronous JavaScript and XML">AJAX</abbr>.  What
works well in Firefox, may not seem like it's working in IE.
 I learned this the hard way.  The application I implemented
<abbr title="Asynchronous JavaScript and XML">AJAX</abbr> on
is my personal online checkbook register.  So the idea was
to allow a user to stay on one page, add a new transaction,
submit it, and have the list show the latest transaction
while also changing the account balance all without
refreshing the window.  This worked great in Firefox, yet
nothing seemed to be happening in IE.  When in actuality,
the database inserts were definitely happening, yet the list
and account balance refresh was not.  It took me a while to
figure out what and why this was happening, but finally
figured it out when I came across this article "<a
href="http://www.enja.org/david/?p=25">Ajax IE caching
issue</a>".  It seems as though IE believes that GET
requests (<code>method="get"</code>) need to be cached,
while POST requests do not.  This meant changing all my
requests from GETs to POSTs.  Finding out how to do this
took a bit of research as well, so I'm going to just give
this to you here (if you already know how to do this, then
feel free to ignore the following).  The solution, as you'll
see is extremely simple (changes are marked in <span
class="highlight"><strong><em>bold &amp;
italic</em></strong></span>):<br />
<strong>Example GET request:</strong></p>
<p class="blockcode">
function insertRow() {<br />
		&nbsp;&nbsp;var url = 'ajax_file.cfm';<br />
		&nbsp;&nbsp;var param1 = $F('p1');<br />
                &nbsp;&nbsp;var param2 = $F('p2');<br />
                &nbsp;&nbsp;var param3 = $F('p3');<br />
		&nbsp;&nbsp;var pars = 'P1='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param1<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ '&P2='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param2<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ '&P3='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param3;<br />
		&nbsp;&nbsp;var myAjax = new Ajax.Request(<br />
			&nbsp;&nbsp;&nbsp;&nbsp;url,<br />
			&nbsp;&nbsp;&nbsp;&nbsp;{<br />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method: 'get',<br />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parameters: pars,<br
/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;onComplete:
runNextFunction<br />
			&nbsp;&nbsp;&nbsp;&nbsp;});<br />
}
</p>
<p><strong>Example changed to a POST request:</strong></p>
<p class="blockcode">
function insertRow() {<br />
		&nbsp;&nbsp;var url = 'ajax_file.cfm';<br />
		&nbsp;&nbsp;var param1 = $F('p1');<br />
                &nbsp;&nbsp;var param2 = $F('p2');<br />
                &nbsp;&nbsp;var param3 = $F('p3');<br />
		&nbsp;&nbsp;var pars = 'P1='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param1<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ '&P2='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param2<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ '&P3='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param3;<br />
		&nbsp;&nbsp;var myAjax = new Ajax.Request(<br />
			&nbsp;&nbsp;&nbsp;&nbsp;url,<br />
			&nbsp;&nbsp;&nbsp;&nbsp;{<br />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method: '<span
class="highlight"><strong><em>post</em></strong></span>',<br
/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span
class="highlight"><strong><em>postBody</em></strong></span>:
pars,<br />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;onComplete:
runNextFunction<br />
			&nbsp;&nbsp;&nbsp;&nbsp;});<br />
}
</p>
<p>Well there you have it. The IE issue is fixed, right? 
Well...  Not exactly.  This solution only seemed to work
part of the time.  So, after some more digging, I found the
definitive solution.  Although not elegant, it fixes the
problem.  That solution is to add a random number parameter
onto the end of the parameters that get passed.  "Why would
this work?" you might ask.  Well this random number will
basically fool the browser into thinking it has to return a
page from a URL it's never been to before, rather than
thinking it has it in cache (<a
href="http://www.crackajax.net/cachebust.php">learn
more</a>).</p>
<p><strong>POST Example with Random Number</strong></p>
<p class="blockcode">
function insertRow() {<br />
		&nbsp;&nbsp;var url = 'ajax_file.cfm';<br />
		&nbsp;&nbsp;var param1 = $F('p1');<br />
                &nbsp;&nbsp;var param2 = $F('p2');<br />
                &nbsp;&nbsp;var param3 = $F('p3');<br />
		&nbsp;&nbsp;var pars = 'P1='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param1<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ '&P2='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param2<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ '&P3='<br />
                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+ param3;<br />
				    <strong><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+
'&rnd='<br />
				    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+
Math.random()*99999;</em></strong> //using rather large
multiplier to ensure uniqueness<br />
		&nbsp;&nbsp;var myAjax = new Ajax.Request(<br />
			&nbsp;&nbsp;&nbsp;&nbsp;url,<br />
			&nbsp;&nbsp;&nbsp;&nbsp;{<br />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method: 'post',<br
/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;postBody: pars,<br
/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;onComplete:
runNextFunction<br />
			&nbsp;&nbsp;&nbsp;&nbsp;});<br />
}
</p>
<p>I feel that the information in this article is exactly
what is needed to get your feet wet with <abbr
title="Asynchronous JavaScript and XML">AJAX</abbr>.  I plan
to create a <a
href="http://weblog.patmullin.com/?p=47">tutorial that will
walk you through a real world working example of <abbr
title="Asynchronous JavaScript and XML">AJAX</abbr> using
ColdFusion</a> and a simple MS Access Database.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patmullin.com/weblog/2006/02/22/my-first-ajax-experience/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Site Breakdown: Part I &#8211; Header</title>
		<link>http://www.patmullin.com/weblog/2006/01/27/site-breakdown-part-i-header/</link>
		<comments>http://www.patmullin.com/weblog/2006/01/27/site-breakdown-part-i-header/#comments</comments>
		<pubDate>Thu, 26 Jan 2006 23:07:53 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.patmullin.com/weblog/?p=43</guid>
		<description><![CDATA[I spent a considerable amount of my free time on this site, and enjoyed every single second of it. Perhaps a little too much (ask my wife). Since I've spent so much time, and have learned a ton while doing so, I feel that it's only right, as a designer who utilized information from other [...]]]></description>
			<content:encoded><![CDATA[<p>I spent a considerable amount of my free time on this
site, and enjoyed every single second of it.  Perhaps a
little too much (ask my wife).  Since I've spent so much
time, and have learned a ton while doing so, I feel that
it's only right, as a designer who utilized information from
other blogs to create this one, to give a relatively
detailed breakdown of this site.  Since this will be
somewhat detailed, I've decided to break it down into
parts:</p>
<ul>
<li>Part I - Header</li>
<li>Part II - Body</li>
<li>Part III - Sidebar</li>
<li>Part IV - Footer</li>
<li>(links to the above list will be added as the entries
are written)</li>
</ul>
<p><span id="more-43"></span><br />
<strong>The Header</strong><br />
<a
href="http://www.patmullin.com/tricklin/images/tricklin_logo
_200x60.png"><img
src="http://www.patmullin.com/tricklin/images/tricklin_logo_
200x60.png" alt="Entire Tricklin Logo" class="floatright"
/></a>The masthead consists of the logo and the navigation. 
This may not seem like a whole lot, yet some really nice
<abbr title="Cascading Style Sheets">CSS</abbr> code is
utilized here, making for some really clean markup, and a
nice user experience.  We'll start with the logo.<br />
<strong>The Logo</strong><br />
The <a
href="http://www.patmullin.com/tricklin/images/tricklin_logo
_200x60.png" title="Click here to view the entire logo
image.">image</a> itself is actually part of the background.
 Notice, when looking at the <abbr title="eXtensible
HyperText Markup Language">XHTML</abbr>, there is no
reference to the logo image itself:</p>
<p class="blockcode">
&lt;div id="logo"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;a href="http://www.tricklin.com"
name="top"&gt;Tricklin&lt;/a&gt;<br />
&lt;/div&gt;
</p>
<p>The beauty of this is that the logo image is in the
background, declared in the <abbr title="Cascading Style
Sheets">CSS</abbr>.  To help clarify, let's take a look at
this code:</p>
<p class="blockcode">
#logo {<br />
&nbsp;&nbsp;&nbsp;&nbsp;margin: 0 0 0 6px;<br />
&nbsp;&nbsp;&nbsp;&nbsp;position:relative;<br />
&nbsp;&nbsp;&nbsp;&nbsp;float:left;<br />
&nbsp;&nbsp;&nbsp;&nbsp;width:200px;<br />
}<br />
#logo a {<br />
&nbsp;&nbsp;&nbsp;&nbsp;height:60px;<br />
&nbsp;&nbsp;&nbsp;&nbsp;width:200px;<br />
&nbsp;&nbsp;&nbsp;&nbsp;background:
url(http://www.patmullin.com/tricklin/images/tricklin_logo_2
00x60.png) no-repeat;<br />
&nbsp;&nbsp;&nbsp;&nbsp;text-indent: -9000px;<br />
&nbsp;&nbsp;&nbsp;&nbsp;display:block;<br />
}<br />
#logo a:hover {<br />
&nbsp;&nbsp;&nbsp;&nbsp;background-position: 0 -60px;<br />
}
</p>
<p>The first section, <code>#logo</code>, acts as the
placeholder for the logo image.  By looking at this we know
that the logo will appear on the left of the screen, and a
margin of 6 pixels will keep it from butting directly up
against the left edge of the browser window.  We also know
that since the image is only 200 pixels in width, that is
the widest we need this section to be, so it is set to 200
pixels.</p>
<p>The remaining sections, <code>#logo a</code> and
<code>#logo a:hover</code>, are what declare the logo image,
and the properties that make it clickable.  We'll start with
the default link state.  First, <code>#logo a</code> means
that an anchor tag within the "<code>logo</code>" div will
aquire these properties.  Meaning all other anchor tags will
not be affected.  That said, the anchor tag inside
"<code>#logo</code>" will place the
"tricklin_logo_200x60.png" into the background and only show
it once (<code>no-repeat</code>).  If otherwise declared,
the starting point for showing the image is 0 pixels from
the left and 0 pixels from the top.  As you can see from the
actual logo image (above), it's actually 120 pixels in
height, yet the image will only appear in an available
window that is 60 pixels tall.  So the user will only see
the top-half of the logo image.  So that when the mouse is
"hovered (<code>#logo a:hover</code>)" over the logo, the
bottom half of the logo will appear in the available window
- <code>background-position:0 -60px</code>.</p>
<p><strong>Navigation Menu</strong><br />
Once again, the markup for the navigation is nice and clean.
 There are no image references in the actual <abbr
title="eXtensible HyperText Markup Language">XHTML</abbr>
code.  Let's have a look:</p>
<p class="blockcode">
&lt;div id="navigation"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;ul class="nav"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&l
t;a href="http://www.patmullin.com/portfolio.cfm"
accesskey="1"
class="portfolio"&gt;&lt;span&gt;portfolio&lt;/span&gt;&lt;/
a&gt;&lt;/li&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&l
t;a href="http://www.patmullin.com/contact_me.cfm"
accesskey="2" class="contactme"&gt;&lt;span&gt;contact
me&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&l
t;a href="http://www.patmullin.com/about_me.cfm"
accesskey="3"
class="aboutme"&gt;&lt;span&gt;projects&lt;/span&gt;&lt;/a&g
t;&lt;/li&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&l
t;a href="http://weblog.patmullin.com" accesskey="4"
class="weblog_c"&gt;&lt;span&gt;journal&lt;/span&gt;&lt;/a&g
t;&lt;/li&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/ul&gt;<br />
&lt;/div&gt;
</p>
<p>Notice that each "button" has an <a
href="http://www.alistapart.com/articles/accesskeys/"
title="Click here to learn more about
accesskeys.">accesskey</a> associated to it.  These were
added to improve the accessibility of the site.  Since  <a
href="http://www.designmeme.com">Stuart Robertson</a> does
an excellent job explaining accesskeys in his <a
href="http://www.alistapart.com/articles/accesskeys/"
title="Click here to learn more about
accesskeys.">article</a> on <a
href="http://www.alistapart.com">A List Apart</a>, I won't
go into detail about this.  </p>
<p>With some <abbr title="Cascading Style Sheets">CSS</abbr>
coding, the navigation menu goes from looking like a
bulleted list to a horizontal set of buttons:</p>
<p class="blockcode">
#navigation ul.nav {<br />
&nbsp;&nbsp;&nbsp;&nbsp;padding: 0px;<br />
&nbsp;&nbsp;&nbsp;&nbsp;margin: 0px;<br />
}<br />
#navigation ul.nav li {<br />
&nbsp;&nbsp;&nbsp;&nbsp;display: inline;<br />
&nbsp;&nbsp;&nbsp;&nbsp;list-style-type: none;<br />
&nbsp;&nbsp;&nbsp;&nbsp;margin: 0;<br />
&nbsp;&nbsp;&nbsp;&nbsp;padding: 0;<br />
}<br />
#navigation ul.nav li a{<br />
&nbsp;&nbsp;&nbsp;&nbsp;float:left;<br />
&nbsp;&nbsp;&nbsp;&nbsp;display: block;<br />
&nbsp;&nbsp;&nbsp;&nbsp;list-style-type: none;<br />
&nbsp;&nbsp;&nbsp;&nbsp;margin: 0px;<br />
&nbsp;&nbsp;&nbsp;&nbsp;padding: 0;<br />
}
</p>
<p>Each button in the navigation menu has 3 states (using
only 1 image), a mouser over (<code>hover</code>), a mouse
out, and an active page state.  Each state is represented
using the same concept as with the logo:</p>
<p class="blockcode">
#navigation ul.nav li a.portfolio, #navigation ul.nav li
a.portfolio_c, #navigation ul.nav li a.portfolio:hover{<br
/>
&nbsp;&nbsp;&nbsp;&nbsp;width: 90px;<br />
&nbsp;&nbsp;&nbsp;&nbsp;height: 30px;<br />
&nbsp;&nbsp;&nbsp;&nbsp;background:
url(http://www.patmullin.com/images/portfolio_nav_tab2.png)
no-repeat;<br />
}<br />
#navigation ul.nav li a.portfolio{background-position:0
-50px;}  // mouse out state<br />
#navigation ul.nav li a.portfolio_c{background-position:0
-100px;}  // active page state<br />
#navigation ul.nav li
a.portfolio:hover{background-position:0 0;}  // mouse over
state
</p>
<p>So, that's the header in a nutshell.  Next, I'll explain
the Body, and all the little CSS elements and WordPress
plugins used.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patmullin.com/weblog/2006/01/27/site-breakdown-part-i-header/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zebra Striping Tables in ColdFusion, using CSS and JavaScript</title>
		<link>http://www.patmullin.com/weblog/2005/11/05/zebra-striping-tables-in-coldfusion-using-css-and-javascript/</link>
		<comments>http://www.patmullin.com/weblog/2005/11/05/zebra-striping-tables-in-coldfusion-using-css-and-javascript/#comments</comments>
		<pubDate>Fri, 04 Nov 2005 22:39:31 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.patmullin.com/weblog/?p=28</guid>
		<description><![CDATA[Want to create a table that contains rows of alternating color? This is a little tutorial dedicated to showing you how. I've also added a third color to the mix. This will be used as a highlighting tool when the user mouses over a row. Let's start by having a look at the XHTML and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.patmullin.com/cigar_list.cfm"
title="Click here to see alternating row color in
action."><img
src="http://www.patmullin.com/images/striping.png"
class="floatright" alt="Striped Table" /></a>Want to create
a table that contains rows of alternating color?  This is a
little tutorial dedicated to showing you how.  I've also
added a third color to the mix.  This will be used as a
highlighting tool when the user mouses over a row.  Let's
start by having a look at the XHTML and ColdFusion code.<br
/>
<strong>XHTML and ColdFusion:</strong></p>
<p class="blockcode">
&lt;table&gt;<br />
&lt;cfoutput query="EmployeeList"&gt;<br />
&lt;cfset rowid = "#EmployeeList.EmployeeID#"&gt;<br />
&nbsp;&nbsp;&lt;tr class="#IIF(CurrentRow MOD 2, DE('dark'),
DE('light'))#" id="#rowid#"
onmouseover="changeBgcolor('#rowid#','rollovercolor');"
onmouseout="changeBgcolor('#rowid#','#IIF(CurrentRow MOD 2,
DE('dark'), DE('light'))#');"&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;...<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/td&gt;<br />
&nbsp;&nbsp;&lt;/tr&gt;<br />
&lt;/cfoutput&gt;<br />
&lt;/table&gt;
</p>
<p>Since the main idea here is to alternate the colors
between rows, the key set of code from the above example is
the following: <code>currentrow MOD 2</code>.  What in the
heck does this mean?</p>
<blockquote><p>
ColdFusion offers a modulus function (MOD) that returns the
remainder (modulus) after a number is divided by a divisor;
for example,10 MOD 3 is 1.  -- <a
href="http://livedocs.macromedia.com/coldfusion/6.1/htmldocs
/main_ap9.htm">livedocs.macromedia.com</a>
</p></blockquote>
<p>Since even numbers divided by the number 2 will divide
evenly (i.e. no remainder), and odd numbers when divided by
2 will not, we use <code>CurrentRow MOD 2</code>.</p>
<blockquote><p>The CurrentRow variable is one of a few
variables that ColdFusion automatically exposes that provide
information about the query. These variables are often
called query variables. -- <a
href="http://livedocs.macromedia.com/coldfusion/6.1/htmldocs
/main_ap9.htm">livedocs.macromedia.com</a></p></blockquote>
<p><span id="more-28"></span>Based on what we know now,
let's look at the entire "<code>IIF</code>" statement:</p>
<p class="blockcode">#IIF(CurrentRow MOD 2, DE('dark'),
DE('light'))#</p>
<p>In ColdFusion, the "<code>IIF</code>" statement works
like this:</p>
<p class="blockcode">#IIF(<em>conditional statement</em>,
<em>RETURN THE EXACT STRING:('value returned if the
conditional statement is true')</em>, <em>RETURN THE EXACT
STRING:('value returned if the conditional statement is
false')</em>)#</p>
<p>To help clarify the above even more, this:
<code>class="#IIF(CurrentRow MOD 2, DE('dark'),
DE('light'))#"</code>, as a story would read "if the
remainder of the current row divided by the number 2 is
greater than zero (0), then the class will equal 'dark',
otherwise, the class will be 'light'.</p>
<p>Now that we've taken care of the alternating rows, let's
incorporate that 3rd color which will be used for
highlighting a row.  Before we go any further, let's first
take a look at the JavaScript code.<br />
<strong>Javascript:</strong></p>
<p class="blockcode">
// Determine browser<br />
var isMinIE5 = (navigator.appVersion.indexOf("5.")) >= 0 ? 1
: 0;<br />
var isDOM = (document.getElementById) ? 1 : 0;<br />
function changeBgcolor(objId,objClass) {<br />
&nbsp;&nbsp;if (isMinIE5||isDOM) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById(objId).class
Name=objClass;<br />
&nbsp;&nbsp;} else {<br />
&nbsp;&nbsp;&nbsp;&nbsp;return;<br />
&nbsp;&nbsp;}<br />
}
</p>
<p>This is just a simple javascript that will change the
class name of the id being passed to the function
(<code>objId</code>) to the a new class which is also being
passed to the function (<code>objClass</code>).  These
classes are simple <code>background-color</code>
declarations in the CSS:</p>
<p class="blockcode">
.light {<br />
&nbsp;&nbsp;background-color: #fff;<br />
}<br />
.dark {<br />
&nbsp;&nbsp;background-color: #efefef;<br />
}<br />
.rollovercolor {<br />
&nbsp;&nbsp;background-color:#ccc;<br />
}
</p>
<p>So, when looking at the following piece of code:
<code>onmouseover="changeBgcolor('#rowid#','rollovercolor');
"</code>, we can determine that when the user mouses over
the row, the class name of the id '#rowid#' will change to
'rollovercolor'.  </p>
<p>At this point you may be asking, what is this
'<code>#rowid#</code>'?  In order for this entire set of
code to function properly, we need to guarantee that the
'<code>id</code>' for the row (a.k.a. the 'tr') is unique. 
That is where this '<code>#rowid#</code>' comes into
play:</p>
<p class="blockcode">
&lt;cfoutput query="EmployeeList"&gt;<br />
&lt;cfset rowid = "#EmployeeList.EmployeeID#"&gt;
</p>
<p>All database tables must have a column that contains a
unique identifier, called the primary key (most of the
time).  In the example above, we're setting the
'<code>rowid</code>' to be equal to the "EmployeeID", which
in this case is the unique identifier for the "Employee"
table.  The reason for putting this value into a variable
called "<code>rowid</code>" is so that you don't have to add
"<code>#EmployeeList.EmployeeID#</code>" into the row's code
3 different times.  It also makes it easier when you want to
use this code in another section of your application!</p>
<p>The last thing that we need, is to make sure we set the
classes back to what they were originally when the user
moves the mouse off the row.  So we need to add an
"<code>onmouseout</code>" action:
<code>onmouseout="changeBgcolor('#rowid#','#IIF(CurrentRow
MOD 2, DE('dark'), DE('light'))#');"</code></p>
<p>There you have it.  A way to represent a table of
information in a cleaner, easier to navigate fashion.<br />
<a href="http://www.patmullin.com/cigar_list.cfm"
title="Click here to see the alternating rows in action">See
alternating rows in action</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.patmullin.com/weblog/2005/11/05/zebra-striping-tables-in-coldfusion-using-css-and-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finally Implemented sIFR</title>
		<link>http://www.patmullin.com/weblog/2005/10/28/finally-implemented-sifr/</link>
		<comments>http://www.patmullin.com/weblog/2005/10/28/finally-implemented-sifr/#comments</comments>
		<pubDate>Thu, 27 Oct 2005 19:49:59 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.patmullin.com/weblog/?p=23</guid>
		<description><![CDATA[As of today 10/27/2005, I've implemented sIFR on my website. What's that? So what? What in the h*** is sIFR? Well, if you look at the title of this article above (and all other titles), you'll notice that it's font is the same as the logo's font. The best part: it's not an image. That's [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mikeindustries.com/sifr/"><img
src="http://www.mikeindustries.com/blog/images/inline/logo_s
ifr2.gif" alt="sIFR 2.0"class="floatright" /></a>As of today
10/27/2005, I've implemented sIFR on my website.  What's
that?  So what?  What in the h*** is sIFR?  Well, if you
look at the title of this article above (and all other
titles), you'll notice that it's font is the same as the
logo's font.  The best part:  it's not an image.  That's
right, it's an <code>&lt;h2&gt;</code> heading.  Thanks to
the magic of <a href="http://www.mikeindustries.com">Mike
Davidson</a> and <a
href="http://http://novemberborn.net/">Mark Wubben</a>, it
is now possible to use any font you wish for your headings,
without having to create images.</p>
<blockquote><p>
sIFR is meant to replace short passages of plain browser
text with text rendered in your typeface of choice,
regardless of whether or not your users have that font
installed on their systems. It accomplishes this by using a
combination of javascript, CSS, and Flash. -- <a
href="http://www.mikeindustries.com/sifr/">http://www.mikein
dustries.com/sifr/</a>
</p></blockquote>
<p>Implementation was relatively simple.  Just follow the
directions, and your on your way!  <a
href="http://www.mikeindustries.com/sifr/">Learn more and
download</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patmullin.com/weblog/2005/10/28/finally-implemented-sifr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

