<?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; Tutorials</title>
	<atom:link href="http://www.patmullin.com/weblog/category/tutorials/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>Awesome Tables With Very Little Markup</title>
		<link>http://www.patmullin.com/weblog/2008/02/11/awesome-tables-with-very-little-markup/</link>
		<comments>http://www.patmullin.com/weblog/2008/02/11/awesome-tables-with-very-little-markup/#comments</comments>
		<pubDate>Tue, 12 Feb 2008 01:46:48 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.patmullin.com/weblog/2008/02/11/awesome-tables-with-very-little-markup/</guid>
		<description><![CDATA[Creating nice looking tables in HTML can be quite annoying. You have to give the table an ID or class, then give each row a class or give each column a class. Then you have to add some crazy code to make each row alternate color and another set of crazy javascript to make the [...]]]></description>
			<content:encoded><![CDATA[<p>Creating nice looking tables in HTML can be quite
annoying.  You have to give the table an ID or class, then
give each row a class or give each column a class.  Then you
have to add some crazy code to make each row alternate color
and another set of crazy javascript to make the rows
highlight when you mouse over them.  Well...  That is no
longer the case.  Below is an example of how to get nice
looking HTML tables with very little code or markup.</p>
<p><strong>Use Tables For Tables Only!</strong><br />
First things first, if your page is using tables for layout,
then stop reading.  This solution is for people who only use
tables for their intended purpose.  So, make sure you are
using tables correctly before continuing on.</p>
<p><strong>The Table Markup</strong><br />
The actual XHTML code for the tables themselves is extremely
simple, and because of this is, it is nice and legible.<br
/>
<span id="more-109"></span></p>
<pre class="brush: html">
&lt;table&gt;
    &lt;thead&gt;
        &lt;tr&gt;
            &lt;th&gt;Column Head&lt;/th&gt;
        &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;Column Value&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
</pre>
<p><strong>Give It a Little Style</strong><br />
Now that you have the HTML down, it's time to give this
table it's looks.</p>
<pre class="brush: css">
table {
    border-collapse: collapse; /* removes unwanted
cellspacing garbage */
    border-top: 1px solid #999;
    border-left: 1px solid #999;
    margin-bottom: 20px;
}

table thead {
    background: #ccc;
	text-transform: uppercase;
}

table thead th {
    border-bottom: 2px solid #333;
}

table thead th, table tbody td {
    padding: 5px 10px;
    border-right: 1px solid #999;
}

table tbody td {
    border-bottom: 1px solid #999;
}
</pre>
<p>Here's what you get:<br />
<img
src="http://www.patmullin.com/weblog/wp-content/uploads/2008
/02/screen-capture.png" alt="Table with no row colors"
/></p>
<p>Looks nice, eh?  We're not done yet.  Now we want to make
each row alternate color and make each row change to a
different color when you mouse over it.  To do this, we need
a little JavaScript.</p>
<pre class="brush: javascript">
function niceTables(evenclass,oddclass,hiliteclass) {
    if(document.getElementsByTagName(&#039;table&#039;)) {
		var tables =
document.getElementsByTagName(&#039;table&#039;);
		for (var nn = 0; nn &lt; tables.length; nn++) {
		  var rows = tables[nn].tBodies[0].rows;
            for(var ii = 0; ii &lt; rows.length; ii++) {
		    	var row = rows[ii];
		    	row.onmouseover = function () {
                        this.className=hiliteclass;
                    };
		    	if(ii % 2) {
		    		row.className = evenclass;
		    		row.onmouseout = function () {
		    		        this.className=evenclass;
		    		    };
		    	} else {
		    		row.className = oddclass;
		    		row.onmouseout = function () {
		    		        this.className=oddclass;
		    		    };
		    	}
		    }
		}
	}
}
</pre>
<p>This will set the class of all rows that are divisible by
2 to the variable <code>evenclass</code> and all other rows
to the variable <code>oddclass</code>.  It will also set a
mouse over event on the row and when moused over change the
class to the <code>hiliteclass</code>.  So this is great and
all, but how do I get this function to run?  Simple... We're
going to add an onload event to the window with javascript
like this:</p>
<pre class="brush: javascript">
window.onload=function(){
    niceTables(&#039;light&#039;, &#039;dark&#039;,
&#039;hilite&#039;);
}
</pre>
<p>So, if this javascript included in the <code>head</code>
of all your html files, then every table that exists in the
page will obtain this style when the page loads.  Notice
that calling this function set the <code>evenclass</code> to
'light', the <code>oddclass</code> to 'dark', and the
<code>hilite</code> class to 'hilite'.  What this means, is
that we have to add these classes to our stylesheet:</p>
<pre class="brush: css">
.light {
    background: #fff;
}

.dark {
    background: #DFEEFF;
}

.hilite {
    background: #9FCDFF;
}
</pre>
<p>...and you end up with:<br />
<img
src='http://www.patmullin.com/weblog/wp-content/uploads/2008
/02/screen-capture-1.png' alt='Tables with alternatiing row
colors' /></p>
<p>There you have it, nice, sleek looking tables with very
little markup.  <a
href="http://www.patmullin.com/awesome_tables.html">See it
in action</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patmullin.com/weblog/2008/02/11/awesome-tables-with-very-little-markup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving Windows With Your Keyboard</title>
		<link>http://www.patmullin.com/weblog/2007/04/01/moving-windows-with-your-keyboard/</link>
		<comments>http://www.patmullin.com/weblog/2007/04/01/moving-windows-with-your-keyboard/#comments</comments>
		<pubDate>Mon, 02 Apr 2007 01:29:46 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.patmullin.com/weblog/2007/04/01/moving-windows-with-your-keyboard/</guid>
		<description><![CDATA[The other day, I disconnected my dual display monitor from my laptop, and forgot that I had a few windows opened up in the now disabled display. Which meant that I couldn't see them, and couldn't use my mouse to drag them into view. This was extremely annoying, because the window I cared about was [...]]]></description>
			<content:encoded><![CDATA[<p>The other day, I disconnected my dual display monitor
from my laptop, and forgot that I had a few windows opened
up in the now disabled display.  Which meant that I couldn't
see them, and couldn't use my mouse to drag them into view. 
This was extremely annoying, because the window I cared
about was the "find & replace" window in my Dreamweaver. 
With a little bit of research, I figured out that I could
move the window with a few little keyboard shortcuts.</p>
<ol>
<li>Hit Alt + Tab until the window you need moved is
enabled</li>
<li>Hit Alt + Spacebar</li>
<li>Type "m"</li>
<li>Use the arrow keys in direction you wish the window to
move</li>
</ol>
<p>And that is all!  Hopefully this little tip will help
you, like it helped me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patmullin.com/weblog/2007/04/01/moving-windows-with-your-keyboard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>Another IE Bug: Unnecessarily Duplicating Text</title>
		<link>http://www.patmullin.com/weblog/2006/08/25/another-ie-bug-unnecessarily-duplicating-text/</link>
		<comments>http://www.patmullin.com/weblog/2006/08/25/another-ie-bug-unnecessarily-duplicating-text/#comments</comments>
		<pubDate>Thu, 24 Aug 2006 20:29:35 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.patmullin.com/weblog/?p=65</guid>
		<description><![CDATA[This issue has puzzled me for quite some time, and finally after some research I was able to figure out just what the heck was going on. The Problem For some odd and seemingly unexplainable reason, IE will display duplicate/repeating characters even though the code does not represent this. ... &#160;&#160;&#160;&#160;&#160;&#160;&#60;div id="thumbnails" style="display:none;"&#62;&#60;/div&#62; &#160;&#160;&#160;&#160;&#160;&#160;&#60;div id="story" [...]]]></description>
			<content:encoded><![CDATA[<p>This issue has puzzled me for quite some time, and
finally after some research I was able to figure out just
what the heck was going on.</p>
<h3>The Problem</h3>
<p>For some odd and seemingly unexplainable reason, IE will
display duplicate/repeating characters even though the code
does not represent this.</p>
<p class="blockcode">
...<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div
id="thumbnails" style="display:none;"&gt;&lt;/div&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id="story"
style="position:relative;float:right;"&gt;<br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt
;p
style="position:relative;float:right;"&gt;01.01.01&lt;/p&gt;
<br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt
;h2&gt;Title&lt;/h2&gt;<br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt
;p&gt;Lorem Ipsum ...&lt;/p&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;<br />
	&nbsp;&nbsp;&nbsp;&lt;/div&gt;<br />
        &nbsp;&nbsp;&nbsp;&lt;div id="footer"&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;a
href="http://xxx" title="Click here to go to the main
page."&gt;home&lt;/a&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;nbsp;|&amp;nbsp;<
br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;a
href="http://xxx" title="Click here to go to the about
page."&gt;about&lt;/a&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;nbsp;|&amp;nbsp;<
br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;a
href="http://xxx" title="Click here to go to the photos
page."&gt;photos&lt;/a&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;nbsp;|&amp;nbsp;<
br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;a href="http://xxx
title="Click here to go to the contact us
page."&gt;contact&lt;/a&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;nbsp;||&amp;nbsp;
<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;a
href="http://xxx" title="Click here to go to the site
map."&gt;site map&lt;/a&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;br /&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;copy;&amp;nbsp;20
06 &nbsp;&lt;a
href="http://www.tricklin.com"&gt;tricklin.com&lt;/a&gt;<br
/>
	&nbsp;&nbsp;&nbsp;&lt;/div&gt;<br />
        &nbsp;&nbsp;&nbsp;&lt;!-- end 'footer' --&gt;<br />
&lt;/div&gt;<br />
&lt;!-- end 'page' --&gt;<br />
...
</p>
<p><span id="more-65"></span></p>
<p>Looks pretty legit, right?  Well it is.  Except IE
doesn't render it correctly:</p>
<p><a
href="http://www.patmullin.com/images/ie_duplicate_bug.png"
target="_new" title="Click here to view a larger image"><img
src="http://www.patmullin.com/images/ie_duplicate_bug_small.
png" alt="IE duplicate / repeat text bug" class="floatleft"
/></a>.</p>
<h3>Why?</h3>
<p>Well, after doing a bit of research, here is what I
found:</p>
<blockquote><p>
The direct cause is nothing more than ordinary HTML
comments, such as, <code>&lt;!-- end left column
--&gt;</code>, sandwiched between floats that come in
sequence. Apparently, the comments are hard for IE to digest
when they occupy those positions, resulting in a kind of
"screen diarrhea". HTML comments inside the floats do not
cause the bug, nor do comments before or after the float
series. Only comments residing between floats cause the bug.
-- <a
href="http://www.positioniseverything.net/explorer/dup-chara
cters.html">positioniseverything.net</a>
</p></blockquote>
<p><strong>AND</strong></p>
<blockquote><p>
It turns out that this duplicating characters bug can be
triggered by other things than just HTML comments. Phil
Baines points out that any elements given the style
<code>{display: none}</code> will also induce the bug. In
fact, even hidden inputs can do it, and presumably any other
elements that don't actually display for some reason.
Apparently the act of hiding a source element is the
critical trigger for this bug. -- <a
href="http://www.positioniseverything.net/explorer/dup-chara
cters.html">positioniseverything.com</a>
</p></blockquote>
<p>After knowing this, can you guess what I needed to do to
the above code?  That's correct.</p>
<h3>The Solution</h3>
<p class="blockcode">
...<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id="story"
style="position:relative;float:right;"&gt;<br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt
;p
style="position:relative;float:right;"&gt;01.01.01&lt;/p&gt;
<br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt
;h2&gt;Title&lt;/h2&gt;<br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt
;p&gt;Lorem Ipsum ...&lt;/p&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;div
id="thumbnails"
style="display:none;"&gt;&lt;/div&gt;</strong> 
<strong>&laquo; move div here</strong><br />
        &nbsp;&nbsp;&nbsp;&lt;div id="footer"&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;a
href="http://xxx" title="Click here to go to the main
page."&gt;home&lt;/a&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;nbsp;|&amp;nbsp;<
br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;a
href="http://xxx" title="Click here to go to the about
page."&gt;about&lt;/a&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;nbsp;|&amp;nbsp;<
br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;a
href="http://xxx" title="Click here to go to the photos
page."&gt;photos&lt;/a&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;nbsp;|&amp;nbsp;<
br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;a href="http://xxx
title="Click here to go to the contact us
page."&gt;contact&lt;/a&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;nbsp;||&amp;nbsp;
<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;a
href="http://xxx" title="Click here to go to the site
map."&gt;site map&lt;/a&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;br /&gt;<br />
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;copy;&amp;nbsp;20
06 &nbsp;&lt;a
href="http://www.tricklin.com"&gt;tricklin.com&lt;/a&gt;<br
/>
	&nbsp;&nbsp;&nbsp;&lt;/div&gt;<br />
        &nbsp;&nbsp;&nbsp;&lt;!-- end 'footer' --&gt;<br />
&lt;/div&gt;<br />
<span style="color:red;font-weight:bold">remove this
altogether &raquo;</span> <em><strong>&lt;!-- end 'page'
--&gt;</strong></em><br />
...
</p>
<p>There you have it.  Another IE issue that needs a
workaround.  Hopefully this helps a few people from going
insane.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patmullin.com/weblog/2006/08/25/another-ie-bug-unnecessarily-duplicating-text/feed/</wfw:commentRss>
		<slash:comments>3</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>Static Rating System Using One Image &amp; Some CSS</title>
		<link>http://www.patmullin.com/weblog/2005/12/01/static-rating-system-using-one-image-some-css/</link>
		<comments>http://www.patmullin.com/weblog/2005/12/01/static-rating-system-using-one-image-some-css/#comments</comments>
		<pubDate>Wed, 30 Nov 2005 19:04:48 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.patmullin.com/weblog/?p=34</guid>
		<description><![CDATA[After seeing Rogie King's 5 star rating tool which he created using CSS and only 1 image, I was inspired to create a similar, static version (i.e. a way to represent a score once it's already been set). For example, I wanted a way to represent a score of 3 out of 4 stars, or [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.patmullin.com/static_rating.html"
title="Click here to see the static rating system in
action."><img
src="http://www.patmullin.com/images/star_rating.png"
class="floatright" alt="Star Rating System" /></a>After
seeing <a href="http://weblog.patmullin.com/?p=3">Rogie
King's 5 star rating tool</a> which he created using <abbr
title="Cascading Style Sheets">CSS</abbr> and only 1 image,
I was inspired to create a similar, <a
href="http://www.patmullin.com/static_rating.html"
title="Click here to see the static rating system in
action.">static version</a> (i.e. a way to represent a score
once it's already been set).  For example, I wanted a way to
represent a score of 3 out of 4 stars, or 2 out of 4 stars,
using the <a href="http://www.patmullin.com/star.png">same
image</a> for both examples.  So, using <a
href="http://komodomedia.com/">Mr. King's</a> <a
href="http://komodomedia.com/blog/index.php/2005/08/24/creat
ing-a-star-rater-using-css/">concept</a>, I was able to come
up with an easy way to implement a light-weight static
rating system.  Let's start with the image:</p>
<p><img src="http://www.patmullin.com/images/star_desc.png"
alt="Image description of the star." /></p>
<p><strong>The <abbr title="Cascading Style
Sheets">CSS</abbr>:</strong></p>
<p class="blockcode">
.score{<br />
	margin: 0px;<br />
	padding:0px;<br />
	width: 80px;<br />
	height: 20px;<br />
	background: url(star.png) top left repeat-x;<br />
}
</p>
<p><span id="more-34"></span>We begin by establishing the
area where the entire score will reside.  As you can see,
the area will be 80 pixels in width and 20 pixels in height.
 Because of this criteria, we know that this will be a 4
star rating system.  How do we know this?  Because the width
of the entire <code>score</code> area is set to 80 pixels,
and each star is 20 pixels in width (see image above):  80 /
20 = 4.  If we wanted 5 stars, we'd simply add 20 pixels,
making the total width <code>100px</code>.  We also know,
that will will only see the empty stars: 
<code>height:<strong>20px</strong></code> and
<code>background: url(star.png) <strong>top left
repeat-x</strong>;</code>.  Now, all we need to consider is
how to represent each rating.  First off, since each rating
will share similar <abbr title="Cascading Style
Sheets">CSS</abbr> characterisitcs we'll combine them into
one set:</p>
<p class="blockcode">
.score_1, .score_2, .score_3, .score_4 {<br />
	margin: 0px;<br />
	padding: 0px;<br />
	height: 20px;<br />
	position: absolute;<br />
	font-size: 8px;<br />
	text-decoration: none;<br />
	text-indent: -9000px;<br />
	background: url(star.png) bottom left repeat-x;<br />
}
</p>
<p>Based on the above, we see that each of these scores will
use the bottom half of <code>star.png</code>: <code>height:
<strong>20px</strong></code> and <code>background:
url(star.png) <strong>bottom left</strong> repeat-x</code>. 
We also know that no text will appear in the browser:
<code>text-indent: -9000px;</code>.  I've set the font size
to 8 pixels in order to guarantee that the layout won't be
compromised.  If it were to be set to a size greater than 20
pixels, you'd see some not too pleasing results.  Now that
we've got the shared attributes decided, the only thing left
to do is establish the widths of each score separately. 
This is what will give each score it's unique
presentation:</p>
<p class="blockcode">
.score_1 {<br />
	width:20px;<br />
}<br />
.score_2 {<br />
	width:40px;<br />
}<br />
.score_3 {<br />
	width:60px;<br />
}<br />
.score_4 {<br />
	width:80px;<br />
}
</p>
<p>How does this work?  Because, each score's background is
repeated horizontally yet each contains a different width:
<code>background: url(star.png) bottom left
<strong>repeat-x</strong>;</code>.  So <code>score_1</code>
will repeat, yet it will only be 20 pixels in width. 
Whereas <code>score_4</code> will repeat and be 80 pixels in
width, in effect showing all 4 stars.</p>
<p><strong>What does the <abbr title="eXtensible HyperText
Markup Language">XHTML</abbr> look like?</strong></p>
<p class="blockcode">
&lt;h2&gt;A score of 1&lt;/h2&gt;<br />
&lt;div class="score"&gt;<br />
	&lt;span class="score_1"&gt;1&lt;/span&gt;<br />
&lt;/div&gt;<br />
&lt;h2&gt;A score of 2&lt;/h2&gt;<br />
&lt;div class="score"&gt;<br />
	&lt;span class="score_2"&gt;2&lt;/span&gt;<br />
&lt;/div&gt;<br />
&lt;h2&gt;A score of 3&lt;/h2&gt;<br />
&lt;div class="score"&gt;<br />
	&lt;span class="score_3"&gt;3&lt;/span&gt;<br />
&lt;/div&gt;<br />
&lt;h2&gt;A score of 4&lt;/h2&gt;<br />
&lt;div class="score"&gt;<br />
	&lt;span class="score_4"&gt;4&lt;/span&gt;<br />
&lt;/div&gt;
</p>
<p>There you have it, a simple, easy way to represent a
static rating system using a single image and some <abbr
title="Cascading Style Sheets">CSS</abbr>.  <a
href="http://www.patmullin.com/static_rating.html"
title="Click here to see the static rating system in
action.">See it in action</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.patmullin.com/weblog/2005/12/01/static-rating-system-using-one-image-some-css/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>
	</channel>
</rss>

