<?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>MisterSender&#039;s Blog</title>
	<atom:link href="http://www.triadwebcrafters.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.triadwebcrafters.com/blog</link>
	<description>documenting my struggles as an independant web programmer</description>
	<lastBuildDate>Fri, 13 Aug 2010 21:15:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How the facebook like button works</title>
		<link>http://www.triadwebcrafters.com/blog/?p=54</link>
		<comments>http://www.triadwebcrafters.com/blog/?p=54#comments</comments>
		<pubDate>Fri, 13 Aug 2010 21:15:12 +0000</pubDate>
		<dc:creator>mistersender</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Social Media]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[facebook]]></category>

		<guid isPermaLink="false">http://www.triadwebcrafters.com/blog/?p=54</guid>
		<description><![CDATA[exploring exactly what the facebook like button does behind the scenes when it is added to a web page.]]></description>
			<content:encoded><![CDATA[<div>
<p>I was recently working on a project involving the facebook &#8220;like&#8221; button and how it creates links back to the place of origin.  For the vast majority of websites, simply implementing the code found in the facebook documentation is enough, however, I was dealing with a different sort of monster.  The site I wanted to implement the like button on was self-replicating, using a url rewrite rule to handle replication.  To prevent duplicate content, a canonical url tag was listed in the header.  I noticed upon implementation of the facebook like button that the posted links were returning to the specified canonical url in the page header instead of the url I specified in my like tag.  This caused me to want to investigate how facebook’s like button works.  Below are my findings.</p>
<p>Upon clicking the “like” button, whether using the &lt;iframe&gt; or js SDK version of the like button, an AJAX call was sent out to facebook (of course).  Facebook would search, in this order, for the first of the following:</p>
<ol>
<li>facebook’s own open graph      protocol meta tag</li>
<li>the canonical url meta tag</li>
<li>a specified url in the actual      like button</li>
<li>the current page’s url</li>
</ol>
<p>Once determining the URL based on the above, facebook would then crawl the correct page sniffing for (in this order):</p>
<ol>
<li>facebook’s own open graph      protocol meta tags</li>
<li>any other data it could glean      to get what it needed (ie, a meta description, the title, etc)</li>
</ol>
<p>It would use the gathered information to then build the post on the user’s wall correctly.  However, in certain circumstances, specifying your own og tag was not enough.</p>
<p>In the event a user clicks the “like” button, but does not enter the optional comment, the link posted on the user’s wall actually linked back to the canonical URL.  Interestingly, the fan page that facebook creates for your page is properly linked using the og:url you specify.  We all know, however, that most users will click on the news feed link instead of the page’s.  Below are the tests I ran to verify what was happening:</p>
<div>
<table border="2" cellspacing="0" width="1027">
<tbody>
<tr valign="top">
<td bgcolor="#606060"><strong>canonical</strong></td>
<td bgcolor="#606060"><strong>OG<br />
tag</strong></td>
<td bgcolor="#606060"><strong>comment</strong></td>
<td bgcolor="#606060"><strong>Finding</strong></td>
<td bgcolor="#606060"><strong>screenshot</strong></td>
<td bgcolor="#606060"><strong>Conclusion</strong></td>
</tr>
<tr valign="top">
<td>YES</td>
<td>YES</td>
<td>YES</td>
<td>properly linked, extra info included</td>
<td><img class="alignnone size-full wp-image-58" title="1" src="http://www.triadwebcrafters.com/blog/wp-content/uploads/2010/08/1.jpg" alt="1" width="477" height="146" /></td>
<td>Best case scenario but cannot force<br />
someone to comment.  OG tags will create fan pages for any page<br />
someone “likes”.</td>
</tr>
<tr valign="top">
<td>YES</td>
<td>YES</td>
<td>NO</td>
<td>Improperly linked on feed, but properly<br />
linked in all extra info that is included (fig 1)<br />
Note: on page refresh, it appears facebook<br />
crawled the correct web page and added a link to the root of the site:<br />
(still improperly linked (fig 2)</td>
<td>1.<img class="alignnone size-full wp-image-59" title="2.1" src="http://www.triadwebcrafters.com/blog/wp-content/uploads/2010/08/2.1.jpg" alt="2.1" width="485" height="219" /></p>
<p>2. <img class="alignnone size-full wp-image-60" title="2.2" src="http://www.triadwebcrafters.com/blog/wp-content/uploads/2010/08/2.2.jpg" alt="2.2" width="401" height="23" /></td>
<td>Could get around with use of a rel param<br />
that would be sent in url.  Would require framework change to support.</td>
</tr>
<tr valign="top">
<td>YES</td>
<td>NO</td>
<td>YES</td>
<td>improperly linked everywhere</td>
<td><img class="alignnone size-full wp-image-61" title="3" src="http://www.triadwebcrafters.com/blog/wp-content/uploads/2010/08/3.jpg" alt="3" width="417" height="101" /></td>
<td>Current implementation on live.<br />
not acceptable</td>
</tr>
<tr valign="top">
<td>YES</td>
<td>NO</td>
<td>NO</td>
<td>Improperly linked (fig 1)<br />
Edit: on page refresh, it appears facebook<br />
crawled the canonical index page and picked up the extra info on it<br />
included in the canonical og tags: (still improperly linked, but extra<br />
info from canonical page included) (fig 2)</td>
<td>1.<img class="alignnone size-full wp-image-62" title="4.1" src="http://www.triadwebcrafters.com/blog/wp-content/uploads/2010/08/4.1.jpg" alt="4.1" width="336" height="27" /></p>
<p>2. <img class="alignnone size-full wp-image-63" title="4.2" src="http://www.triadwebcrafters.com/blog/wp-content/uploads/2010/08/4.2.jpg" alt="4.2" width="423" height="19" /></td>
<td>Current implementation on live.<br />
not acceptable</td>
</tr>
<tr valign="top">
<td>NO</td>
<td>YES</td>
<td>YES</td>
<td>Properly Linked, extra info included,<br />
more likely to appear in news feed.</td>
<td><img class="alignnone size-full wp-image-64" title="5" src="http://www.triadwebcrafters.com/blog/wp-content/uploads/2010/08/5.jpg" alt="5" width="461" height="141" /></td>
<td>cannot implement—canonical must be<br />
defined.</td>
</tr>
<tr valign="top">
<td>NO</td>
<td>YES</td>
<td>NO</td>
<td>Properly Linked, with<br />
extra info included</td>
<td><img class="alignnone size-full wp-image-65" title="6" src="http://www.triadwebcrafters.com/blog/wp-content/uploads/2010/08/6.jpg" alt="6" width="453" height="153" /></td>
<td>cannot implement—canonical must be<br />
defined.</td>
</tr>
<tr valign="top">
<td>NO</td>
<td>NO</td>
<td>YES</td>
<td>Properly linked, extra info<br />
gotten from other meta tags in header</td>
<td><img class="alignnone size-full wp-image-66" title="7" src="http://www.triadwebcrafters.com/blog/wp-content/uploads/2010/08/7.jpg" alt="7" width="540" height="111" /></td>
<td>cannot implement—canonical must be<br />
defined.</td>
</tr>
<tr valign="top">
<td>NO</td>
<td>NO</td>
<td>NO</td>
<td>Properly Linked</td>
<td><img class="alignnone size-full wp-image-57" title="8" src="http://www.triadwebcrafters.com/blog/wp-content/uploads/2010/08/8.jpg" alt="8" width="316" height="24" /></td>
<td>cannot implement—canonical must be<br />
defined.</td>
</tr>
</tbody>
</table>
</div>
<p><span style="font-family: Arial; font-size: small;">All tests were run with the facebook javascript SDK Like button implementation method as comments are not<br />
allowed with &lt;iframe&gt;s in the size we need.</span></p>
<p><span style="font-family: Arial; font-size: x-small;"><span style="font-size: 10pt; font-family: Arial;">Facebook has created a “rel” attribute that can be sent in with a like button, which is returned regardless of the url facebook chooses to show.  Theoretically, the issue of what page facebook posts could be gotten around with a sniffer in your code that looks for a url param of “fb_rel” and redirects accordingly.</span></span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.triadwebcrafters.com/blog/?feed=rss2&amp;p=54</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft Office Guide Cheat Sheets</title>
		<link>http://www.triadwebcrafters.com/blog/?p=50</link>
		<comments>http://www.triadwebcrafters.com/blog/?p=50#comments</comments>
		<pubDate>Fri, 26 Mar 2010 15:58:36 +0000</pubDate>
		<dc:creator>mistersender</dc:creator>
				<category><![CDATA[xhtml/css]]></category>
		<category><![CDATA[cheat sheet]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[microsoft]]></category>

		<guid isPermaLink="false">http://www.triadwebcrafters.com/blog/?p=50</guid>
		<description><![CDATA[These got e-mailed to me recently and I thought they were worth sharing.  Just some pdf&#8217;s with a cheat sheet of how to use a lot of MSOffice tools&#8230; even IE (boo!)
Microsoft Office Guide Cheat Sheets
Enjoy!
]]></description>
			<content:encoded><![CDATA[<p>These got e-mailed to me recently and I thought they were worth sharing.  Just some pdf&#8217;s with a cheat sheet of how to use a lot of MSOffice tools&#8230; even IE (boo!)</p>
<p><a href="http://www.customguide.com/quick_references.htm">Microsoft Office Guide Cheat Sheets</a></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.triadwebcrafters.com/blog/?feed=rss2&amp;p=50</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coldfusion Code Efficiency Tips</title>
		<link>http://www.triadwebcrafters.com/blog/?p=44</link>
		<comments>http://www.triadwebcrafters.com/blog/?p=44#comments</comments>
		<pubDate>Thu, 18 Mar 2010 18:38:07 +0000</pubDate>
		<dc:creator>mistersender</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[cfscript]]></category>
		<category><![CDATA[structure]]></category>

		<guid isPermaLink="false">http://www.triadwebcrafters.com/blog/?p=44</guid>
		<description><![CDATA[This is as summary of what I&#8217;ve learned about code efficiency in the past
couple of weeks.  A lot of the things I didn&#8217;t even think about are actually
wrong, or at least not as efficient as they could be.  The general idea is to
cut back on evaluation as much as possible.
Using structKeyExists() instead of [...]]]></description>
			<content:encoded><![CDATA[<p>This is as summary of what I&#8217;ve learned about code efficiency in the past<br />
couple of weeks.  A lot of the things I didn&#8217;t even think about are actually<br />
wrong, or at least not as efficient as they could be.  The general idea is to<br />
cut back on evaluation as much as possible.</p>
<h3>Using structKeyExists() instead of isDefined()</h3>
<p>Think about it, ALL coldfusion variables are in structures, right?  So<br />
instead of <strong>isDefined(&#8217;myvar&#8217;)</strong> where coldfusion doesn&#8217;t know what struct to start<br />
in and therefore has to look through every scope to find the instance of myvar<br />
and see if it exists, you are now telling coldfusion exactly where to look using<br />
<strong>structKeyExists(&#8217;variables&#8217;, &#8216;myvar&#8217;)</strong>.  It&#8217;s the difference between someone<br />
saying &#8220;turn to page 123 paragraph 2 on Insects&#8221; and &#8220;find the part about Insects&#8221;.  Well, you can go to the index in the book and look at all of the places Insects are mentioned, or you can just go to the page because the information was given to you&#8230; much better!</p>
<h3>Looping</h3>
<p>Everyone has done it, the classic loop through a list.  Here&#8217;s how it would<br />
look:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#listlen(mylist)#&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #0000FF;">#i#</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Ok, that&#8217;s decent code, and certainly what you will find out there as the<br />
&#8220;standard&#8221; way of doing things, but this can be more efficient:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> loopThrough<span style="color: #0000FF;">=</span><span style="color: #0000FF;">listlen</span><span style="color: #0000FF;">&#40;</span>mylist<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#loopThrough#&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #0000FF;">#i#</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Why?  Instead of having to not only loop through your list x number of times,<br />
the first example would also be evaluating #listlen(mylist)# x times as well&#8230;<br />
twice the effort!  It&#8217;s much less taxing on the system to define variables than<br />
to re-evaluate over and over&#8230; even if it is less characters on the page.</p>
<h3>If it&#8217;s boolean, don&#8217;t bother with the &#8220;eq 1&#8243; or &#8220;neq NO&#8221; etc.</h3>
<p>If you are going to have a boolean returned by a variable, don&#8217;t bother<br />
setting what it&#8217;s equal to, you&#8217;re just wasting space, plus your code looks<br />
cleaner.  Examples:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> isEfficient <span style="color: #0000FF;">=</span> <span style="color: #FF0000;">1</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> isEfficient<span style="color: #0000FF;">&gt;</span></span>it's efficient!<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> isEfficient <span style="color: #0000FF;">=</span> <span style="color: #009900;">'1'</span><span style="color: #0000FF;">&gt;</span></span>It's NOT as efficient.<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>The variable above, &#8220;isEfficient&#8221; could also be set to any of these boolean<br />
combinations and it would still work:</p>
<ul>
<li>yes/no</li>
<li>true/false</li>
<li>1 (OR ANY numeric value that is NOT 0&#8230; yes, that means &#8216;-.000001&#8242; &#038;<br />
 59990289 will both evaluate True) / 0</li>
</ul>
<h3>Eliminate &#8220;Else&#8221; from If statements where possible.</h3>
<p>If you&#8217;re like me, this one seemed ridiculous, right?  I know I thought I<br />
only used &#8220;else&#8221; when necessary, but I was SO wrong.  I have to admit though,<br />
this is a method that is really used more on the presentation side than the<br />
logic side, even though you can apply it to both.  Let&#8217;s see an example.</p>
<p>This is a pretty classic example.  Let&#8217;s say we have a bunch of table rows we<br />
want to have with colors that fluxuate by row.  First, we&#8217;ll look at the if/else<br />
way:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;5&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
 <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> NOT mod<span style="color: #0000FF;">&#40;</span>i<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">td</span> <span style="color: #0000FF;">style</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;color: red&quot;</span><span style="color: #0000FF;">&gt;</span></span>&amp;nbsp;<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">td</span><span style="color: #0000FF;">&gt;</span></span>
 <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfelse</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">td</span> <span style="color: #0000FF;">style</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;color: blue&quot;</span><span style="color: #0000FF;">&gt;</span></span>&amp;nbsp;<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">td</span><span style="color: #0000FF;">&gt;</span></span>
 <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Let&#8217;s see what we can do to Improve.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--add to css style--&gt;</span>
.line0 {color: red}
.line1 {color: blue}
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;5&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;i&quot;</span><span style="color: #0000FF;">&gt;</span></span>
 <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">td</span> <span style="color: #0000FF;">class</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;line#mod(i)#&quot;</span><span style="color: #0000FF;">&gt;</span></span>&amp;nbsp;<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">td</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Much Better!  But there is more to it than just this example.  Let&#8217;s look at<br />
a different example:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> isWidgets <span style="color: #0000FF;">=</span> <span style="color: #FF0000;">1</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> isWidgets<span style="color: #0000FF;">&gt;</span></span>
 <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">p</span><span style="color: #0000FF;">&gt;</span></span>There are widgets!<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">p</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfelse</span><span style="color: #0000FF;">&gt;</span></span>
 <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">p</span><span style="color: #0000FF;">&gt;</span></span>There aren't any widgets...<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">p</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Ok, so this might not be the most efficient thing to do in every situation,<br />
but as this is an example to build on, here&#8217;s how we could eliminate the<br />
&#8220;else&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> isWidgets <span style="color: #0000FF;">=</span> <span style="color: #FF0000;">1</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> widgetText <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;There aren't any Widgets...&quot;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> isWidgets<span style="color: #0000FF;">&gt;</span></span>
 <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> widgetText <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;There are widgets!&quot;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">p</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #0000FF;">#widgetText#</span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">p</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>It&#8217;s important to note that doing this:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> isWidgets <span style="color: #0000FF;">=</span> <span style="color: #FF0000;">1</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> widgetText <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> isWidgets<span style="color: #0000FF;">&gt;</span></span>
 <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> widgetText <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;There are widgets!&quot;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfelse</span><span style="color: #0000FF;">&gt;</span></span>
 <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> widgetText <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;There aren't any Widgets...&quot;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">p</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #0000FF;">#widgetText#</span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">p</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Is even less efficient than the first example, because you not only still<br />
have an else statement, but more variables and more characters floating about.<br />
Therefore, we could also glean that starting off by defining a variable with one<br />
of the options for its value is another way to reduce code and increase<br />
efficiency&#8230; of course, that&#8217;s not possible in many situations, but where it is, it&#8217;s a good idea.</p>
<h3>Use cfscript</h3>
<p>I always shied away from this tag in the past.  I was a self taught cf&#8217;er and<br />
while I certainly love the simplicity of the tag based cf language, cfscript<br />
isn&#8217;t as scary as I thought.  You pretty much just strip the &#8220;cf&#8221; off of the<br />
tags and add some &#8220;;&#8221;.  Sure, there&#8217;s a little more to it, but really, you can<br />
figure it out!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.triadwebcrafters.com/blog/?feed=rss2&amp;p=44</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coldfusion Instance Variables</title>
		<link>http://www.triadwebcrafters.com/blog/?p=39</link>
		<comments>http://www.triadwebcrafters.com/blog/?p=39#comments</comments>
		<pubDate>Tue, 16 Mar 2010 14:47:36 +0000</pubDate>
		<dc:creator>mistersender</dc:creator>
				<category><![CDATA[Coldfusion]]></category>

		<guid isPermaLink="false">http://www.triadwebcrafters.com/blog/?p=39</guid>
		<description><![CDATA[This is a term I have heard thrown around a lot by developers, and while I knew
what they were, I never knew I knew it until recently.  So for all of those who
are curious, this is for you.
So, Let&#8217;s say we have a very simple cfc:

&#60;cfcomponent displayname=&#34;MyCFC&#34;&#62;
 &#60;cffunction name=&#34;getList&#34; access=&#34;public&#34; returntype=&#34;struct&#34; output=&#34;false&#34;&#62;
  &#60;cfset [...]]]></description>
			<content:encoded><![CDATA[<p>This is a term I have heard thrown around a lot by developers, and while I knew<br />
what they were, I never knew I knew it until recently.  So for all of those who<br />
are curious, this is for you.</p>
<p>So, Let&#8217;s say we have a very simple cfc:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfcomponent</span> displayname<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;MyCFC&quot;</span><span style="color: #0000FF;">&gt;</span></span>
 <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getList&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;struct&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> returnData <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> i <span style="color: #0000FF;">=</span> <span style="color: #FF0000;">0</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;5&quot;</span><span style="color: #0000FF;">&gt;</span></span>
   <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> returnData <span style="color: #0000FF;">=</span> returnData <span style="color: #0000FF;">&amp;</span> <span style="color: #009900;">','</span> <span style="color: #0000FF;">&amp;</span> i<span style="color: #0000FF;">&gt;</span></span>
   <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> i <span style="color: #0000FF;">=</span> i + <span style="color: #FF0000;">1</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> returnData<span style="color: #0000FF;">/&gt;</span></span>
 <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
 <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getList2&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;struct&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> returnData <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #808080; font-style: italic;">&lt;!---notice this function has no i = 0 set---&gt;</span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;5&quot;</span><span style="color: #0000FF;">&gt;</span></span>
   <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> returnData <span style="color: #0000FF;">=</span> returnData <span style="color: #0000FF;">&amp;</span> <span style="color: #009900;">','</span> <span style="color: #0000FF;">&amp;</span> i<span style="color: #0000FF;">&gt;</span></span>
   <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> i <span style="color: #0000FF;">=</span> i + <span style="color: #FF0000;">1</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> returnData<span style="color: #0000FF;">/&gt;</span></span>
 <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfcomponent</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Ok, so then let&#8217;s say we call getList, and then getList2.  Here&#8217;s what we&#8217;d see:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">getList= ,0,1,2,3,4
getList2= ,5,6,7,8,9</pre></div></div>

<p>So, what happened?  In our getList function, we declared i = 0.  However, we did<br />
NOT declare it as a &#8220;var&#8221; for the function, and that means that &#8220;i&#8221; is available<br />
in ALL of your functions, instead of just that one specific function.  The above<br />
is set up to not really end up being a problem, but what you will eventually run<br />
into is you will have two functions that may get called at once, and if they are<br />
both manipulating the &#8220;i&#8221; variable, things will get weird.  For example, in the<br />
above example, if both functions somehow manage to get called at the same time,<br />
you may end up with an output like this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">getList = ,0,2,3,7,8
getList2 = ,1,4,5,6,9</pre></div></div>

<p>Where this can really come back to bite you is if you have several queries you<br />
have not &#8220;var&#8221; scoped that are all named the same thing.  Perhaps you have<br />
several users that are pulling up user-specific data via these separate queries<br />
in separate functions in your cfc, but you forgot to var scope your queries.<br />
Bam&#8230; your users start seeing each other&#8217;s data occasionally.  Problem?<br />
definitely.  Lesson: make sure to var scope any variables that are NOT cfc-wide.</p>
<p><strong>So</strong>, why did I tell you all that when all you really wanted to know about was<br />
instance variables?  Because &#8220;i&#8221; is an instance variable.  It&#8217;s just a variable<br />
(and yes, they belong to the &#8220;variables&#8221; scope) that is available to all of your functions in a component.  A lot of times, you<br />
will see these variables thrown into the variables scope just to make keeping<br />
them separate easier.  You&#8217;ll also commonly see an &#8220;init()&#8221; function whose job it<br />
is to set all of those instance variables the first time a component is called<br />
just to be sure the variables are available when needed.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfcomponent</span> displayname<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;myCFC&quot;</span><span style="color: #0000FF;">&gt;</span></span>
 <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;init&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;struct&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span> <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;this is the init() function for this component&quot;</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> variables.instance <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">structNew</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> instance.myName <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;Tess McTesterson&quot;</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> instance.dsn <span style="color: #0000FF;">=</span>  <span style="color: #009900;">&quot;myDSN&quot;</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> this<span style="color: #0000FF;">/&gt;</span></span>
 <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
 <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getName&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;struct&quot;</span> output<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> returnData <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> returnData <span style="color: #0000FF;">=</span> variables.instance.myName<span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> returnData<span style="color: #0000FF;">/&gt;</span></span>
 <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfcomponent</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>So using the above example, this:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> theComponent <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">createObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;Component&quot;</span>,<span style="color: #009900;">&quot;myCFC&quot;</span><span style="color: #0000FF;">&#41;</span>.init<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #0000FF;">#theComponent.getName<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>#</span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Would yield:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">Tess McTesterson</pre></div></div>

<p>So, instance variables don&#8217;t have their own scope, like &#8220;variables&#8221; or &#8220;form&#8221;<br />
it&#8217;s just a way to refer to variables that are available in a cfc to all<br />
functions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.triadwebcrafters.com/blog/?feed=rss2&amp;p=39</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What are Session and Application Variables in Coldfusion?</title>
		<link>http://www.triadwebcrafters.com/blog/?p=36</link>
		<comments>http://www.triadwebcrafters.com/blog/?p=36#comments</comments>
		<pubDate>Tue, 16 Feb 2010 02:52:26 +0000</pubDate>
		<dc:creator>mistersender</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[structure]]></category>

		<guid isPermaLink="false">http://www.triadwebcrafters.com/blog/?p=36</guid>
		<description><![CDATA[Ok, just to start, this is not a post for the seasoned coldfusion developer, this is just a &#8220;get an idea of what the heck is going on&#8221; sort of post.  I was attempting to explain a simple coldfusion login and some different options to a friend, and they were simply not understanding the [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, just to start, this is not a post for the seasoned coldfusion developer, this is just a &#8220;get an idea of what the heck is going on&#8221; sort of post.  I was attempting to explain a simple coldfusion login and some different options to a friend, and they were simply not understanding the concept because they didn&#8217;t know about application and session variables, so I thought i&#8217;d tutorialize this for the others out there who are just confused.  Sometimes it&#8217;s the simple stuff that&#8217;s the hardest to start!<br />
First, you should be at least vaguely familiar with <a href="http://www.triadwebcrafters.com/blog/?p=34">Structures.</a>  ok? ok!</p>
<p>There are a few concepts to understand when delving into the world of application and session variables, and i will do my best to avoid using techno talk so you can understand it without having to try too hard.  The first, is what an application.cfm (or application.cfc) file is/does.</p>
<p><strong>What an Application.cfm (or application.cfc) file is/does</strong></p>
<p>An application.cfm file is a hunk of code that is executed FIRST before any page you create runs.  You MUST name it &#8220;application.cfm&#8221;.  It MUST be at the root of your site (well, not always, but for the basics, yes&#8230; must.)<br />
Here is what your 1-page website should look like utilizing an application.cfm:</p>
<p>SITEROOT.com<br />
&#8211;index.cfm<br />
&#8211;application.cfm</p>
<p>Let&#8217;s have a look-see here and show you what this will do.</p>
<p>Here&#8217;s my ridiculous application.cfm file:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">I'm an application.</pre></div></div>

<p>And the index:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">I'm a sweet index page.</pre></div></div>

<p>Which will output this:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">I'm an application.I'm a sweet index page.</pre></div></div>

<p>So, we understand.  Applications run first, ALWAYS.  I&#8217;m sure this gets your head turning on the nice things you can now do, but this, my friend, is only the tip of the glorious application file iceberg. There are many, many things you can and should use the application file for, but I don&#8217;t want to overwhelm you, so I will just get you excited about application variables. </p>
<p>All right.  There are some variables that coldfusion makes available to you that you can use on any page, anywhere, always. These are APPLICATION variables.  any variable that you set in the application structure is available anywhere in your website, and is the SAME FOR ALL CLIENTS.</p>
<p>Need to have your datasource name saved? set it!</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> application.dsn<span style="color: #0000FF;">=</span><span style="color: #009900;">'mydsn'</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Now you can just call your datasource name variable instead of hard coding it in.  Why?  you ask?  because you really, really don&#8217;t want people to be able to see your DSN when an error page appears.  yeah, not good.  they&#8217;ll just see the variable name, though if you use the code above!</p>
<p>Mmk, so application variables are for any computer accessing your site, anywhere on your site.</p>
<p><strong>So What is a Session Variable, then?</strong></p>
<p>Unlike Application variables, which (again), once set, can be used by ANY computer, ANY where on your site,  Session variables can only be used by ONE computer ANY where on your site. Here is a great example of where session variables would be perfect:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> session.userid<span style="color: #0000FF;">=</span><span style="color: #FF0000;">1287</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>What does the code above do?  it sets up a userid that can be used anywhere on the site, but only for the one particular computer accessing your site.  This is one way that you could create a secured back end area for different users without having to pass a url or form variable to every page.  Maybe you would like to display a person&#8217;s name on some pages of your site, now you can!  just set it on one page, and then call it when you need it from any other page.  as long as the user is still on your site, their name will appear!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.triadwebcrafters.com/blog/?feed=rss2&amp;p=36</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is a coldfusion structure?</title>
		<link>http://www.triadwebcrafters.com/blog/?p=34</link>
		<comments>http://www.triadwebcrafters.com/blog/?p=34#comments</comments>
		<pubDate>Tue, 16 Feb 2010 02:15:59 +0000</pubDate>
		<dc:creator>mistersender</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[101]]></category>
		<category><![CDATA[structure]]></category>

		<guid isPermaLink="false">http://www.triadwebcrafters.com/blog/?p=34</guid>
		<description><![CDATA[Well, someone told me they heard the word &#8220;structure&#8221; get thrown around a lot in coldfusion, but they weren&#8217;t really clear on what it was.  I thought i&#8217;d write a VERY basic overview of structures and coldfusion for those who don&#8217;t have the luxury of better-informed-colleagues to ask.
Ok, so you know how you can [...]]]></description>
			<content:encoded><![CDATA[<p>Well, someone told me they heard the word &#8220;structure&#8221; get thrown around a lot in coldfusion, but they weren&#8217;t really clear on what it was.  I thought i&#8217;d write a VERY basic overview of structures and coldfusion for those who don&#8217;t have the luxury of better-informed-colleagues to ask.<br />
Ok, so you know how you can read variables in coldfusion, right?  Well, just to be thorough, let&#8217;s review by getting the &#8220;oid&#8221; from the url:</p>
<p>url: website.com?oid=124</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #0000FF;">#url.oid#</span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>And you get:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">124</pre></div></div>

<p>Easy peasy, right?  now for those of you that don&#8217;t know, &#8220;url.oid&#8221; is, like many coldfusion variables, a STRUCTURE.  Here are some other examples of structures just so we are clear:</p>
<p>#url.status#<br />
#form.runadd#<br />
#cart.items.sku#</p>
<p>So, in it&#8217;s most dumbed down form, it&#8217;s just a variable name with some dots thrown in the middle to make them easier to sort, like looking through a list of lists.</p>
<p>Did you know there are some structures available for you to use on EVERY page?  YES!  EVERY page!  And they are super-helpful.  Don&#8217;t believe me? try running this on any coldfusion page:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfdump</span> <span style="color: #000000; font-weight: bold;">var</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#application#&quot;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfdump</span> <span style="color: #000000; font-weight: bold;">var</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#session#&quot;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfdump</span> <span style="color: #000000; font-weight: bold;">var</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#cgi#&quot;</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>So, see all that craziness that gets dumped out?  those are structures!  how do you call one of the things you see&#8230; like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #0000FF;">#cgi.http_server#</span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>and there&#8217;s your http server&#8217;s name.  excellent!  Hopefully this will arm you with the ability to call just about anything you can dump.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.triadwebcrafters.com/blog/?feed=rss2&amp;p=34</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IE Bottom Border Gap Issue</title>
		<link>http://www.triadwebcrafters.com/blog/?p=31</link>
		<comments>http://www.triadwebcrafters.com/blog/?p=31#comments</comments>
		<pubDate>Thu, 14 Jan 2010 19:39:57 +0000</pubDate>
		<dc:creator>mistersender</dc:creator>
				<category><![CDATA[xhtml/css]]></category>

		<guid isPermaLink="false">http://www.triadwebcrafters.com/blog/?p=31</guid>
		<description><![CDATA[Yet another thing IE does that we wish it didn&#8217;t do.  This is simply an image that is SUPPOSED to show up at the bottom of my div, and would therefore hide my background.  Does it? Not in IE.  What&#8217;s the problem, you say?  After a little googling, I tried changing [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_32" class="wp-caption alignright" style="width: 180px"><img src="http://www.triadwebcrafters.com/blog/wp-content/uploads/2010/01/IE_picture_gap.jpg" alt="Background  shows through because this picture doesn&#039;t render at the bottom in IE" title="IE bottom gap issue." width="170" height="62" class="size-full wp-image-32" /><p class="wp-caption-text">Background  shows through because this picture doesn't render at the bottom in IE</p></div>
<p>Yet another thing IE does that we wish it didn&#8217;t do.  This is simply an image that is SUPPOSED to show up at the bottom of my div, and would therefore hide my background.  Does it? Not in IE.  What&#8217;s the problem, you say?  After a little googling, I tried changing my code from this attractive and easy to read version:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">   &lt;img src=&quot;images/banner_bottom.jpg&quot; /&gt;
&lt;/div&gt;</pre></div></div>

<p>To this ugly version that will give me headaches later&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;images/banner_bottom.jpg&quot; /&gt;&lt;/div&gt;</pre></div></div>

<p>yes.  IE decided that empty space was a page break.  Good work IE.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.triadwebcrafters.com/blog/?feed=rss2&amp;p=31</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zero Body Margin in Firefox and IE</title>
		<link>http://www.triadwebcrafters.com/blog/?p=25</link>
		<comments>http://www.triadwebcrafters.com/blog/?p=25#comments</comments>
		<pubDate>Thu, 14 Jan 2010 17:49:36 +0000</pubDate>
		<dc:creator>mistersender</dc:creator>
				<category><![CDATA[xhtml/css]]></category>
		<category><![CDATA[align]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[firefox]]></category>

		<guid isPermaLink="false">http://www.triadwebcrafters.com/blog/?p=25</guid>
		<description><![CDATA[I was working on a project recently where I needed to have my div&#8217;s align to the VERY top of the page, not 10-30px off as is the default preset.  Easy?  I thought it would be.  You can achieve this by using css positioning, but as I had a div within a [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on a project recently where I needed to have my div&#8217;s align to the VERY top of the page, not 10-30px off as is the default preset.  Easy?  I thought it would be.  You can achieve this by using css positioning, but as I had a div within a div, and (as is commonly seen) I wanted the inner div to align to the center, I had a problem.  Again, it sounds easy, but it was more of a pain than it should have been.  Here is a simplified version of what I came up with:</p>
<p>the page&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;teststyle.css&quot;/&gt;
&lt;/head&gt;
&nbsp;
&lt;body&gt;
&nbsp;
&lt;div id=&quot;outer_body&quot;&gt;
	&lt;div id=&quot;inner_body&quot;&gt;
               &lt;div id=&quot;header_text&quot;&gt;
			&lt;h1&gt;Here's a Title!&lt;/h1&gt;
			a tag line here...
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;
&nbsp;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>stylesheet&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #a1a100;">@charset &quot;utf-8&quot;;</span>
<span style="color: #808080; font-style: italic;">/* CSS Document */</span>
&nbsp;
body<span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#e2d6a9</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font</span><span style="color: #3333ff;">:Arial</span><span style="color: #00AA00;">,</span> Helvetica<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#outer_body</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/outer_bg.jpg</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-x</span> <span style="color: #cc00cc;">#0c2110</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
&nbsp;
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#inner_body</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">225px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#0F0</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#header_text</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">40px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">190px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<div id="attachment_27" class="wp-caption alignnone" style="width: 288px"><img src="http://www.triadwebcrafters.com/blog/wp-content/uploads/2010/01/ff_top_align_fail.jpg" alt="Firefox has failed, it&#039;s not easy to align divs at the very top..." title="Firefox top alignment not correct" width="278" height="283" class="size-full wp-image-27" /><p class="wp-caption-text">Firefox has failed, it's not easy to align divs at the very top...</p></div>
<p>This does NOT work by itself, though.  Here&#8217;s the trick.  You have to put something in every div you want to align at the very top of the page that has a margin and a padding of 0px, or you&#8217;re out of luck.  I settled on an image named &#8220;spacer.gif&#8221;, which I then made have a width and height of 0px.  Let&#8217;s see the difference&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!--the index page--&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;teststyle.css&quot;/&gt;
&lt;/head&gt;
&nbsp;
&lt;body&gt;
&nbsp;
&lt;div id=&quot;outer_body&quot;&gt;
	&lt;div id=&quot;inner_body&quot;&gt;
		&lt;img src=&quot;images/logo_bnr.jpg&quot; width=&quot;0&quot; height=&quot;0&quot; id=&quot;spacer&quot; /&gt;
                &lt;div id=&quot;header_text&quot;&gt;
			&lt;h1&gt;Here's a Title!&lt;/h1&gt;
			a tag line here...
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;
&nbsp;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>stylesheet&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #a1a100;">@charset &quot;utf-8&quot;;</span>
<span style="color: #808080; font-style: italic;">/* CSS Document */</span>
&nbsp;
body<span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#e2d6a9</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font</span><span style="color: #3333ff;">:Arial</span><span style="color: #00AA00;">,</span> Helvetica<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
spacer <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#outer_body</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/outer_bg.jpg</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-x</span> <span style="color: #cc00cc;">#0c2110</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
&nbsp;
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#inner_body</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">225px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#0F0</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#header_text</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">40px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">190px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><div id="attachment_26" class="wp-caption alignnone" style="width: 288px"><img src="http://www.triadwebcrafters.com/blog/wp-content/uploads/2010/01/ff_top_align_fix.jpg" alt="With the invisible spacer, added, now everything aligns to the top!" title="Fixed top alignment of 0px" width="278" height="283" class="size-full wp-image-26" /><p class="wp-caption-text">With the invisible spacer, added, now everything aligns to the top!</p></div><br />
Now, a not about IE&#8230; IE + float = issues.  you might have to play around to get what you want in IE.  this solution did work in IE for me, but if you have other elements that are also floating, it could mess those up.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.triadwebcrafters.com/blog/?feed=rss2&amp;p=25</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AJAX/Javascript/Coldfusion Dependent Dropdowns with Optional Text Box</title>
		<link>http://www.triadwebcrafters.com/blog/?p=23</link>
		<comments>http://www.triadwebcrafters.com/blog/?p=23#comments</comments>
		<pubDate>Fri, 18 Dec 2009 19:28:51 +0000</pubDate>
		<dc:creator>mistersender</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Dependent Dropdown]]></category>

		<guid isPermaLink="false">http://www.triadwebcrafters.com/blog/?p=23</guid>
		<description><![CDATA[Here&#8217;s a common problem.  You have a form where you want one select box in a form to be dependent on the other.  Coldfusion makes this ridiculously easy with its built in AJAX functionality.  Let&#8217;s take a gander:
For this example, I set up a cfc called &#8220;ajax&#8221; (clever, eh?).  Here is [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a common problem.  You have a form where you want one select box in a form to be dependent on the other.  Coldfusion makes this ridiculously easy with its built in AJAX functionality.  Let&#8217;s take a gander:</p>
<p>For this example, I set up a cfc called &#8220;ajax&#8221; (clever, eh?).  Here is the function inside it&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;getstates&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;remote&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;array&quot;</span> <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;lookup states for dropdown&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;country&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000FF;">default</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
		<span style="color: #808080; font-style: italic;">&lt;!--- Define variables ---&gt;</span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0000FF;">data</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;&quot;</span><span style="color: #0000FF;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> i<span style="color: #0000FF;">=</span><span style="color: #FF0000;">0</span><span style="color: #0000FF;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> result<span style="color: #0000FF;">=</span><span style="color: #0000FF;">ArrayNew</span><span style="color: #0000FF;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
		<span style="color: #808080; font-style: italic;">&lt;!--- Do search ---&gt;</span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfquery</span> <span style="color: #0000FF;">datasource</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#variables.dsn#&quot;</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;data&quot;</span><span style="color: #0000FF;">&gt;</span></span>
		SELECT state,postal_code
		from tblstates
		where country=<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfqueryparam</span> <span style="color: #0000FF;">value</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#ucase(arguments.country)#&quot;</span> cfsqltype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;cf_sql_varchar&quot;</span><span style="color: #0000FF;">&gt;</span></span>
		order by state
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfquery</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
		<span style="color: #808080; font-style: italic;">&lt;!--- Build result array ---&gt;</span>
		<span style="color: #808080; font-style: italic;">&lt;!--- Convert results to array ---&gt;</span>
        <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;i&quot;</span> <span style="color: #0000FF;">from</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;1&quot;</span> <span style="color: #0000FF;">to</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#data.RecordCount#&quot;</span><span style="color: #0000FF;">&gt;</span></span>
            <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> result<span style="color: #0000FF;">&#91;</span>i<span style="color: #0000FF;">&#93;</span><span style="color: #0000FF;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #0000FF;">&#93;</span><span style="color: #0000FF;">=</span><span style="color: #0000FF;">data</span>.postal_code<span style="color: #0000FF;">&#91;</span>i<span style="color: #0000FF;">&#93;</span><span style="color: #0000FF;">&gt;</span></span>
            <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> result<span style="color: #0000FF;">&#91;</span>i<span style="color: #0000FF;">&#93;</span><span style="color: #0000FF;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #0000FF;">&#93;</span><span style="color: #0000FF;">=</span><span style="color: #0000FF;">data</span>.state<span style="color: #0000FF;">&#91;</span>i<span style="color: #0000FF;">&#93;</span><span style="color: #0000FF;">&gt;</span></span>
        <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
		<span style="color: #808080; font-style: italic;">&lt;!--- And return it ---&gt;</span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> result<span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Mmk, Now let&#8217;s look at the actual code on my form page:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!---here's a query for filling my select box...---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfquery</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;rscountry&quot;</span> <span style="color: #0000FF;">datasource</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#application.db#&quot;</span><span style="color: #0000FF;">&gt;</span></span>
SELECT *
FROM tblcountries
ORDER BY country ASC
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfquery</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!---here's my form---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfform</span> <span style="color: #0000FF;">method</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;post&quot;</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;form1&quot;</span> <span style="color: #0000FF;">action</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;join.cfm?dealeruname=#this_dealer_username#&quot;</span><span style="color: #0000FF;">&gt;</span></span>
     <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfselect</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;country&quot;</span> <span style="color: #0000FF;">id</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;country&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;yes&quot;</span> message<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Please select your country of residence.&quot;</span> <span style="color: #0000FF;">query</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;rscountry&quot;</span> <span style="color: #0000FF;">value</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;country&quot;</span> display<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;country&quot;</span> <span style="color: #0000FF;">selected</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;United States&quot;</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfselect</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
     <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfselect</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;stateprov&quot;</span> bindonload<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span> bind<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;cfc:ajax.getstates({country})&quot;</span> <span style="color: #0000FF;">/&gt;</span></span> 
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfform</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>That&#8217;s it, folks. easy.</p>
<p>But what about when I don&#8217;t have a State listing for say&#8230; Uganda.  Well, we have to have some way of getting the state/province if we don&#8217;t have a populated dropdown.  Now there&#8217;s more to do.  There are probably more elegant solutions out there, but this is what I did, and it seems to work pretty well.</p>
<p>Now we&#8217;re going to need to use some javascript and a bit more ajax.  Let&#8217;s do it!</p>
<p>First, let&#8217;s get our form prepped:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!---here's my sexier form---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfform</span> <span style="color: #0000FF;">method</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;post&quot;</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;form1&quot;</span> <span style="color: #0000FF;">action</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;join.cfm?dealeruname=#this_dealer_username#&quot;</span><span style="color: #0000FF;">&gt;</span></span>
     <span style="color: #808080; font-style: italic;">&lt;!---Notice, I've added an onchange event to this field.---&gt;</span>
     <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfselect</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;country&quot;</span> <span style="color: #0000FF;">id</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;country&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;yes&quot;</span> message<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Please select your country of residence.&quot;</span> <span style="color: #0000FF;">query</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;rscountry&quot;</span> <span style="color: #0000FF;">value</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;country&quot;</span> display<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;country&quot;</span> <span style="color: #0000FF;">selected</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;United States&quot;</span> </span>
<span style="color: #333333;"><span style="color: #0000FF;">onChange</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;showwhich()&quot;</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfselect</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
   <span style="color: #808080; font-style: italic;">&lt;!---wrap each field in a uniquely identified div---&gt;</span>
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">div</span> <span style="color: #0000FF;">id</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;dd_state&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfselect</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;stateprov&quot;</span> bindonload<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span> bind<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;cfc:ajax.getstates({country})&quot;</span> <span style="color: #0000FF;">/&gt;</span></span> 
   <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">div</span><span style="color: #0000FF;">&gt;</span></span>
   <span style="color: #808080; font-style: italic;">&lt;!---add a new text input, and hide it with the div---&gt;</span>
   <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">div</span> <span style="color: #0000FF;">id</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;type_state&quot;</span> <span style="color: #0000FF;">style</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;display:none&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfinput</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;stateprovt&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;text&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>   
   <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">div</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfform</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>OK, we have our text field.  It&#8217;s hidden.  We&#8217;ve got all the other stuff in place, we just need to write the stuff that makes it work!</p>
<p>First, we need to make a new cffunction in our ajax cfc.  The function will return a boolean value for whether or not the country has states/provinces within it.  You could probably set this up to work with your first function, but I went with a smaller query to reduce some load.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;arestates&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;remote&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;boolean&quot;</span> <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;are there states?&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;country&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000FF;">default</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;UNITED STATES&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
		<span style="color: #808080; font-style: italic;">&lt;!--- Define variable ---&gt;</span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0000FF;">data</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
		<span style="color: #808080; font-style: italic;">&lt;!--- Do search ---&gt;</span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfquery</span> <span style="color: #0000FF;">datasource</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#variables.dsn#&quot;</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;data&quot;</span><span style="color: #0000FF;">&gt;</span></span>
		SELECT state
		from tblstates
		where country=<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfqueryparam</span> <span style="color: #0000FF;">value</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#ucase(arguments.country)#&quot;</span> cfsqltype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;cf_sql_varchar&quot;</span><span style="color: #0000FF;">&gt;</span></span>
		LIMIT 1
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfquery</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> <span style="color: #0000FF;">data</span>.recordcount<span style="color: #0000FF;">&gt;</span></span>
			<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> true<span style="color: #0000FF;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfelse</span><span style="color: #0000FF;">&gt;</span></span>
			<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> false<span style="color: #0000FF;">&gt;</span></span>
		<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Ok, not too bad.  Now, let&#8217;s bind our page to the ajax cfc so we can use this function.  Stick this baby at the top of everything on the page:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;">   <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>cfajaxproxy cfc<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;ajax&quot;</span> jsclassname<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;respond&quot;</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Now we need to write the javascript to make the magic happen.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #003366; font-weight: bold;">function</span> showwhich<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	  <span style="color: #003366; font-weight: bold;">var</span> r<span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> respond<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  sforc<span style="color: #339933;">=</span>document.<span style="color: #660066;">form1</span>.<span style="color: #660066;">country</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
	  toshow<span style="color: #339933;">=</span> r.<span style="color: #660066;">arestates</span><span style="color: #009900;">&#40;</span>sforc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>toshow <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> 
	  	<span style="color: #009900;">&#123;</span>
	  	<span style="color: #006600; font-style: italic;">//unhide dropdown, hide text box.</span>
		document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;dd_state&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'inline'</span><span style="color: #339933;">,</span>
		document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;type_state&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'none'</span><span style="color: #339933;">,</span>
		document.<span style="color: #660066;">form1</span>.<span style="color: #660066;">stateprovt</span>.<span style="color: #660066;">value</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span>
		<span style="color: #009900;">&#125;</span>
	  <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">//hide dropdown, unhide text box.</span>
		document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;type_state&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'inline'</span><span style="color: #339933;">,</span>
		document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;dd_state&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'none'</span><span style="color: #339933;">,</span>
		document.<span style="color: #660066;">form1</span>.<span style="color: #660066;">stateprovt</span>.<span style="color: #660066;">value</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span>
	  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You&#8217;ll notice I&#8217;ve added a line to clear the value of the text field on each change.  This is just idiot-proofing so you don&#8217;t have someone come in and enter text, then decide they really did live in the US after all.  I have further idiot proofed by adding this code before my form processes:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> <span style="color: #0000FF;">isdefined</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;form.stateprov&quot;</span><span style="color: #0000FF;">&#41;</span> and <span style="color: #0000FF;">TRIM</span><span style="color: #0000FF;">&#40;</span>form.stateprov<span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">neq</span> <span style="color: #009900;">''</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> use_state<span style="color: #0000FF;">=</span>form.stateprov<span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfelseif</span> <span style="color: #0000FF;">isdefined</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;form.stateprovt&quot;</span><span style="color: #0000FF;">&#41;</span> and <span style="color: #0000FF;">TRIM</span><span style="color: #0000FF;">&#40;</span>form.stateprovt<span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">neq</span> <span style="color: #009900;">''</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> use_state<span style="color: #0000FF;">=</span>form.stateprovt<span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfelse</span><span style="color: #0000FF;">&gt;</span></span>
 	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> runadd<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;no&quot;</span><span style="color: #0000FF;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> message<span style="color: #0000FF;">=</span>message <span style="color: #0000FF;">&amp;</span><span style="color: #009900;">&quot;&lt;br /&gt;The State/Province you entered is invalid.&quot;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Again, I&#8217;m sure there are &#8220;prettier&#8221; ways to accomplish this, but this worked for me!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.triadwebcrafters.com/blog/?feed=rss2&amp;p=23</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>cffile Disappearing Backslashes</title>
		<link>http://www.triadwebcrafters.com/blog/?p=14</link>
		<comments>http://www.triadwebcrafters.com/blog/?p=14#comments</comments>
		<pubDate>Thu, 12 Nov 2009 22:44:37 +0000</pubDate>
		<dc:creator>mistersender</dc:creator>
				<category><![CDATA[Coldfusion]]></category>
		<category><![CDATA[backslashes]]></category>
		<category><![CDATA[bugs]]></category>

		<guid isPermaLink="false">http://www.triadwebcrafters.com/blog/?p=14</guid>
		<description><![CDATA[I&#8217;ve never encountered this one, so I thought I&#8217;d share&#8230;
I was running this simple rename command on an xml response handler page&#8230; very, very simple, right?

&#60;cffile action = &#34;rename&#34; source = &#34;c:\inetpub\mysite\images\tn_0000.png&#34; destination = &#34;c:\inetpub\mysite\images\renamed.png&#34;&#62;

But here was the error I was getting:
Attribute validation error for tag CFFILE. The value of the attribute source, which is [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve never encountered this one, so I thought I&#8217;d share&#8230;</p>
<p>I was running this simple rename command on an xml response handler page&#8230; very, very simple, right?</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffile</span> <span style="color: #0000FF;">action</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;rename&quot;</span> source <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;c:<span style="color: #000099; font-weight: bold;">\i</span>netpub<span style="color: #000099; font-weight: bold;">\m</span>ysite<span style="color: #000099; font-weight: bold;">\i</span>mages<span style="color: #000099; font-weight: bold;">\t</span>n_0000.png&quot;</span> destination <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;c:<span style="color: #000099; font-weight: bold;">\i</span>netpub<span style="color: #000099; font-weight: bold;">\m</span>ysite<span style="color: #000099; font-weight: bold;">\i</span>mages<span style="color: #000099; font-weight: bold;">\r</span>enamed.png&quot;</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>But here was the error I was getting:</p>
<p><strong>Attribute validation error for tag CFFILE. The value of the attribute source, which is currently c:inetpubmysiteimages  tn_0000.png, is invalid.</strong></p>
<p>Whaaat?  where did all my backslashes go??  Well, I don&#8217;t know&#8230; I guess the bermuda triangle of Coldfusion.  Either way, after some trial and error, I found the solution:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffile</span> <span style="color: #0000FF;">action</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;rename&quot;</span> source <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;c:/inetpub/mysite/images/tn_0000.png&quot;</span> destination <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;c:/inetpub/mysite/images/renamed.png&quot;</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>just change them all to forward slashes&#8230; it worked!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.triadwebcrafters.com/blog/?feed=rss2&amp;p=14</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
