<?xml version="1.0" encoding="utf-8"?>

			<rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cc="http://web.resource.org/cc/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">

			<channel>
			<title>iKnowKung(Foo).Blog();</title>
			<link>http://iknowkungfoo.com/blog/index.cfm</link>
			<description>Adrian J. Moreno on ColdFusion, jQuery, HTML5, Web &amp; Mobile Application Architecture</description>
			<language>en-us</language>
			<pubDate>Thu, 17 May 2012 21:48:36 -0500</pubDate>
			<lastBuildDate>Fri, 11 May 2012 19:50:00 -0500</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>blogfoo@iknowkungfoo.com</managingEditor>
			<webMaster>blogfoo@iknowkungfoo.com</webMaster>
			<itunes:subtitle></itunes:subtitle>
			<itunes:summary></itunes:summary>
			<itunes:category text="Technology" />
			<itunes:category text="Technology">
				<itunes:category text="Podcasting" />
			</itunes:category>
			<itunes:category text="Technology">
				<itunes:category text="Tech News" />
			</itunes:category>
			<itunes:keywords></itunes:keywords>
			<itunes:author></itunes:author>
			<itunes:owner>
				<itunes:email>blogfoo@iknowkungfoo.com</itunes:email>
				<itunes:name></itunes:name>
			</itunes:owner>
			
			<itunes:explicit>no</itunes:explicit>
			
			<item>
				<title>ArrayCollection.cfc, a custom JSON renderer for ColdFusion queries</title>
				<link>http://iknowkungfoo.com/blog/index.cfm/2012/5/11/ArrayCollectioncfc-a-custom-JSON-renderer-for-ColdFusion-queries</link>
				<description>
				
				There&apos;s been a few recent blogs posts covering how to convert the JSON returned by ColdFusion&apos;s serializeJSON function to a more standard pattern in order to use data with various grids or JavaScript templates. Those posts covered client-side conversions, here&apos;s how to generate the JSON on the server.&lt;h3&gt;ColdFusion and JSON&lt;/h3&gt;

Let&apos;s use this function, with a simple query:

&lt;code&gt;&lt;cffunction name=&quot;books&quot; access=&quot;remote&quot; output=&quot;false&quot; returntype=&quot;string&quot;&gt;
	&lt;cfargument name=&quot;term&quot; type=&quot;string&quot; required=&quot;true&quot; /&gt;
	&lt;cfset var rs = {} /&gt;
	&lt;cfquery name=&quot;rs.q&quot; datasource=&quot;cfbookclub&quot;&gt;
		SELECT DISTINCT
			bookid,
			title,
			genre
		FROM
			books
		WHERE
			title LIKE &lt;cfqueryparam value=&quot;%#arguments.term#%&quot; cfsqltype=&quot;cf_sql_varchar&quot; /&gt;
		ORDER BY
			genre, title
	&lt;/cfquery&gt;
	&lt;cfreturn serializeJSON( rs.q ) /&gt;
&lt;/cffunction&gt;&lt;/code&gt;

This is using the (case sensitive) Embedded Apache Derby database &quot;cfbookclub&quot; that comes with the base install of ColdFusion. If I make this call:

&lt;code&gt;&lt;cfdump var=&quot;#books(&apos;Man&apos;)# /&gt;&lt;/code&gt;

My JSON will look like this:

&lt;code&gt;{
	&quot;COLUMNS&quot;:[&quot;BOOKID&quot;,&quot;TITLE&quot;,&quot;GENRE&quot;],
	&quot;DATA&quot;:[
		[8,&quot;Apparition Man&quot;,&quot;Fiction&quot;],
		[2,&quot;Shopping Mart Mania&quot;,&quot;Non-fiction&quot;]
	]
}&lt;/code&gt;

If I change the function&apos;s return to &amp;lt;cfreturn serializeJSON( rs.q, true ) /&amp;gt;

&lt;code&gt;{
	&quot;ROWCOUNT&quot;:2,
	&quot;COLUMNS&quot;:[&quot;BOOKID&quot;,&quot;TITLE&quot;,&quot;GENRE&quot;],
	&quot;DATA&quot;:{
		&quot;BOOKID&quot;:[8,2],
		&quot;TITLE&quot;:[&quot;Apparition Man&quot;,&quot;Shopping Mart Mania&quot;],
		&quot;GENRE&quot;:[&quot;Fiction&quot;,&quot;Non-fiction&quot;]
	}
}&lt;/code&gt;

But what we really want is an array of structs. Each struct is an object representation of a row in the query.  This is what I&apos;ve known from Flex development as an &lt;a href=&quot;http://jodieorourke.com/view.php?id=104&amp;blog=news&quot; class=&quot;outbound&quot; target=&quot;_top&quot;&gt;ArrayCollection&lt;/a&gt;.

&lt;code&gt;{	
	&quot;data&quot;:[
		{&quot;bookid&quot;:8,&quot;genre&quot;:&quot;Fiction&quot;,&quot;title&quot;:&quot;Apparition Man&quot;},
		{&quot;bookid&quot;:2,&quot;genre&quot;:&quot;Non-fiction&quot;,&quot;title&quot;:&quot;Shopping Mart Mania&quot;}
	]
}&lt;/code&gt;

&lt;h3&gt;Client-side Conversion&lt;/h3&gt;

Here&apos;s a few blog posts that cover how to convert ColdFusion&apos;s standard JSON to this more standard JSON format:

&lt;ul&gt;
&lt;li&gt;Steve Cutter created the jQuery plugin &lt;a href=&quot;http://www.cutterscrossing.com/index.cfm/2012/5/2/JQuery-Plugin-serializeCFJSON&quot; class=&quot;outbound&quot; target=&quot;_top&quot;&gt;serializeCFJSON&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Ray Camden shows the function &lt;a href=&quot;http://www.raymondcamden.com/index.cfm/2012/5/11/Using-CFC-data-with-Handlebars&quot; class=&quot;outbound&quot; target=&quot;_top&quot;&gt;cfQueryNormalize&lt;/a&gt; to do the same without needing jQuery.&lt;/li&gt;
&lt;/ul&gt;

But we want to serve up our data is this JSON format directly from the server.

&lt;h3&gt;Server-side Conversion&lt;/h3&gt;

The day after Ray put up &lt;a href=&quot;http://www.raymondcamden.com/index.cfm/2012/4/19/Demo-of-Handlebars-and-why-you-should-consider-a-templating-engine&quot; class=&quot;outbound&quot; target=&quot;_top&quot;&gt;his first Handlebars demo&lt;/a&gt;, I got to work using &lt;a href=&quot;http://handlebarsjs.com/&quot; class=&quot;outbound&quot; target=&quot;_top&quot;&gt;Handlebars&lt;/a&gt; in an internal application I&apos;m building. Handlebars is a drop-dead simple JavaScript template engine which I&apos;ll talk more about it later.

A few days ago, Julian Halliwell &lt;a href=&quot;http://cfsimplicity.com/53/simpler-handling-of-json-serialised-coldfusion-query-objects&quot; class=&quot;outbound&quot; target=&quot;_top&quot;&gt;put up a post on this same approach&lt;/a&gt;, but his returns both the original CF JSON and the converted JSON. 

The ArrayCollection.cfc only returns the converted JSON and allows you to convert any query on the fly.

&lt;h3&gt;ArrayCollection.cfc&lt;/h3&gt;

Here&apos;s the CFC, which should always be created as a singleton. Props to Ben Nadel for &lt;a href=&quot;http://www.bennadel.com/blog/124-Ask-Ben-Converting-a-Query-to-an-Array.htm&quot; class=&quot;outbound&quot; target=&quot;_top&quot;&gt;giving me a place to start&lt;/a&gt;.

&lt;code&gt;&lt;cfcomponent&gt;

	&lt;cffunction name=&quot;init&quot; access=&quot;public&quot; output=&quot;false&quot; returntype=&quot;ArrayCollection&quot;&gt;
		&lt;cfset setContentType(&quot;json&quot;) /&gt;
		&lt;cfset setDataHandle(true) /&gt;
		&lt;cfset setDataHandleName(&quot;data&quot;) /&gt;
		&lt;cfreturn this /&gt;
	&lt;/cffunction&gt;

	&lt;cffunction name=&quot;$renderdata&quot; access=&quot;public&quot; output=&quot;false&quot; returntype=&quot;string&quot; hint=&quot;convert a query to an array of structs&quot;&gt;
		&lt;cfset var rs = {} /&gt;
		&lt;cfset var rs.q = variables.data /&gt;
		&lt;cfset rs.results = [] /&gt;
		&lt;cfset rs.columnList = lcase(listSort(rs.q.columnlist, &quot;text&quot; )) /&gt;
		&lt;cfloop query=&quot;rs.q&quot;&gt;
			&lt;cfset rs.temp = {} /&gt;
			&lt;cfloop list=&quot;#rs.columnList#&quot; index=&quot;rs.col&quot;&gt;
				&lt;cfset rs.temp[rs.col] = rs.q[rs.col][rs.q.currentrow] /&gt;
			&lt;/cfloop&gt;
			&lt;cfset arrayAppend( rs.results, rs.temp ) /&gt;
		&lt;/cfloop&gt;
		&lt;cfset rs.data = {} /&gt;
		&lt;cfif hasDataHandle()&gt;
			&lt;cfset rs.data[getDataHandleName()] = rs.results /&gt;
		&lt;cfelse&gt;
			&lt;cfset rs.data = rs.results /&gt;
		&lt;/cfif&gt;
		&lt;cfreturn serializeJSON(rs.data) /&gt;
	&lt;/cffunction&gt;

	&lt;cffunction name=&quot;setData&quot; access=&quot;public&quot; output=&quot;false&quot; returntype=&quot;void&quot;&gt;
		&lt;cfargument name=&quot;data&quot; type=&quot;query&quot; required=&quot;true&quot;&gt;
		&lt;cfset variables.data = arguments.data /&gt;
	&lt;/cffunction&gt;

	&lt;cffunction name=&quot;setContentType&quot; access=&quot;private&quot; output=&quot;false&quot; returntype=&quot;void&quot;&gt;
		&lt;cfargument name=&quot;contenttype&quot; type=&quot;string&quot; required=&quot;true&quot; /&gt;
		&lt;cfset variables.contentType = arguments.contentType /&gt;
	&lt;/cffunction&gt;
	&lt;cffunction name=&quot;getContentType&quot; access=&quot;public&quot; output=&quot;false&quot; returntype=&quot;string&quot;&gt;
		&lt;cfreturn variables.contentType /&gt;
	&lt;/cffunction&gt;

	&lt;cffunction name=&quot;setDataHandle&quot; access=&quot;public&quot; output=&quot;false&quot; returntype=&quot;void&quot;&gt;
		&lt;cfargument name=&quot;datahandle&quot; type=&quot;boolean&quot; required=&quot;true&quot; /&gt;
		&lt;cfset variables.dataHandle = arguments.datahandle /&gt;

	&lt;/cffunction&gt;
	&lt;cffunction name=&quot;hasDataHandle&quot; access=&quot;public&quot; output=&quot;false&quot; returntype=&quot;boolean&quot;&gt;
		&lt;cfreturn variables.dataHandle /&gt;
	&lt;/cffunction&gt;

	&lt;cffunction name=&quot;setDataHandleName&quot; access=&quot;public&quot; output=&quot;false&quot; returntype=&quot;void&quot;&gt;
		&lt;cfargument name=&quot;dataHandleName&quot; type=&quot;string&quot; required=&quot;true&quot; /&gt;
		&lt;cfset variables.dataHandleName = arguments.dataHandleName /&gt;
	&lt;/cffunction&gt;
	&lt;cffunction name=&quot;getDataHandleName&quot; access=&quot;public&quot; output=&quot;false&quot; returntype=&quot;string&quot;&gt;
		&lt;cfreturn variables.dataHandleName /&gt;
	&lt;/cffunction&gt;

&lt;/cfcomponent&gt;&lt;/code&gt;

&lt;h3&gt;Converting a Query&lt;/h3&gt;

Let&apos;s go back to my original function and change it to return an ArrayCollection.

&lt;code&gt;&lt;cfset rs.ac = createObject(&quot;component&quot;, &quot;ArrayCollection&quot;).init() /&gt;
&lt;cfset rs.ac.setData( rs.q ) /&gt;
&lt;cfreturn rs.ac.$renderdata() /&gt;&lt;/code&gt;

You&apos;ve already seen the results:

&lt;code&gt;{	
	&quot;data&quot;:[
		{&quot;bookid&quot;:8,&quot;genre&quot;:&quot;Fiction&quot;,&quot;title&quot;:&quot;Apparition Man&quot;},
		{&quot;bookid&quot;:2,&quot;genre&quot;:&quot;Non-fiction&quot;,&quot;title&quot;:&quot;Shopping Mart Mania&quot;}
	]
}&lt;/code&gt;

So let&apos;s change the data handle:

&lt;code&gt;&lt;cfset rs.ac = createObject(&quot;component&quot;, &quot;ArrayCollection&quot;).init() /&gt;
&lt;cfset rs.ac.setData( rs.q ) /&gt;
&lt;cfset rs.ac.setDataHandleName( &quot;foo&quot; ) /&gt;
&lt;cfreturn rs.ac.$renderdata() /&gt;&lt;/code&gt;

which returns

&lt;code&gt;{	
	&quot;foo&quot;:[
		{&quot;bookid&quot;:8,&quot;genre&quot;:&quot;Fiction&quot;,&quot;title&quot;:&quot;Apparition Man&quot;},
		{&quot;bookid&quot;:2,&quot;genre&quot;:&quot;Non-fiction&quot;,&quot;title&quot;:&quot;Shopping Mart Mania&quot;}
	]
}&lt;/code&gt;

And if we just want the array without a data handle:

&lt;code&gt;&lt;cfset rs.ac = createObject(&quot;component&quot;, &quot;ArrayCollection&quot;).init() /&gt;
&lt;cfset rs.ac.setData( rs.q ) /&gt;
&lt;cfset rs.ac.setDataHandle(false) /&gt;
&lt;cfreturn rs.ac.$renderdata() /&gt;&lt;/code&gt;

will give us just the array

&lt;code&gt;[
	{&quot;bookid&quot;:8,&quot;genre&quot;:&quot;Fiction&quot;,&quot;title&quot;:&quot;Apparition Man&quot;},
	{&quot;bookid&quot;:2,&quot;genre&quot;:&quot;Non-fiction&quot;,&quot;title&quot;:&quot;Shopping Mart Mania&quot;}
]&lt;/code&gt;

&lt;h3&gt;Teaser&lt;/h3&gt;

I&apos;ll post this CFC to github later on, but soon I&apos;ll post an example of using this with Handlebars AND I&apos;ll tell you why I chose the name &lt;strong&gt;$renderdata()&lt;/strong&gt; instead of &lt;strong&gt;renderdata()&lt;/strong&gt;.
				</description>
				
				<category>ColdFusion</category>
				
				<category>Ajax</category>
				
				<category>ColdBox</category>
				
				<pubDate>Fri, 11 May 2012 19:50:00 -0500</pubDate>
				<guid>http://iknowkungfoo.com/blog/index.cfm/2012/5/11/ArrayCollectioncfc-a-custom-JSON-renderer-for-ColdFusion-queries</guid>
				
				
			</item>
			
			<item>
				<title>Upgrading ColdFusion: CFGRID has an inconsistent width attribute</title>
				<link>http://iknowkungfoo.com/blog/index.cfm/2012/5/10/Upgrading-ColdFusion-CFGRID-has-an-inconsistent-width-attribute</link>
				<description>
				
				I&apos;m in the process of moving a massive, years-old application from ColdFusion 8 to ColdFusion 9. I&apos;m also testing on ColdFusion 10 (currently in beta). I&apos;ve run into a few issues and will document them here. First up: Setting the width of a CFGRID.&lt;h3&gt;What is CFGRID?&lt;/h3&gt;

Write a query, pass it to CFGRID and you get a grid of data rendered in either Flash (Flex?) or in HTML/JavaScript via Ext.js. Here&apos;s an example straight from the documentation:

&lt;code&gt;&lt;!--- Query the database to fill up the grid. ---&gt;
&lt;cfquery name = &quot;GetCourses&quot; dataSource = &quot;cfdocexamples&quot;&gt;
	SELECT Course_ID, Dept_ID, CorNumber,
	CorName, CorLevel
	FROM CourseList
	ORDER by Dept_ID ASC, CorNumber ASC
&lt;/cfquery&gt;

&lt;h3&gt;cfgrid Example&lt;/h3&gt;
&lt;i&gt;Currently available courses&lt;/i&gt;
&lt;!--- cfgrid must be inside a cfform tag. ---&gt;
&lt;cfform&gt;
	&lt;cfgrid name = &quot;FirstGrid&quot; format=&quot;Flash&quot;
		height=&quot;320&quot; width=&quot;580&quot;
		font=&quot;Tahoma&quot; fontsize=&quot;12&quot;
		query = &quot;GetCourses&quot;&gt;
	&lt;/cfgrid&gt;
&lt;/cfform&gt;
&lt;/code&gt;

&lt;h3&gt;Documentation&lt;/h3&gt;

&lt;a href=&quot;http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_g-h_03.html&quot; class=&quot;outbound&quot; target=&quot;_top&quot;&gt;Documentation for ColdFusion 8&lt;/a&gt;.
&lt;code&gt;&lt;cfgrid . . . width=&quot;integer&quot;&gt;&lt;/cfgrid&gt;&lt;/code&gt;

&lt;a href=&quot;http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7baf.html&quot; class=&quot;outbound&quot; target=&quot;_top&quot;&gt;Documentation for ColdFusion 9&lt;/a&gt;.
&lt;code&gt;&lt;cfgrid . . . width=&quot;integer&quot;&gt;&lt;/cfgrid&gt;&lt;/code&gt;

&lt;a href=&quot;http://help.adobe.com/en_US/ColdFusion/10.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7baf.html&quot; class=&quot;outbound&quot; target=&quot;_top&quot;&gt;Documentation for ColdFusion 10&lt;/a&gt;.
&lt;code&gt;&lt;cfgrid . . . width=&quot;integer&quot;&gt;&lt;/cfgrid&gt;&lt;/code&gt;

Regardless of version, for &lt;strong&gt;width&lt;/strong&gt;: 

&quot;In HTML format, can be in &lt;strong&gt;&lt;em&gt;any valid CSS measurement unit&lt;/em&gt;&lt;/strong&gt;, and a numeric-only value specifies pixels.&quot;

&lt;h3&gt;LIES!&lt;/h3&gt;

Some of the CFGRIDs currently in use are set to width=&quot;100%&quot; and they&apos;ve been working for &lt;strong&gt;years&lt;/strong&gt;.

&lt;code&gt;
&lt;cfgrid name = &quot;FirstGrid&quot; format=&quot;Flash&quot;
	height=&quot;320&quot; width=&quot;100%&quot; &lt;!--- Works in CF8 ---&gt;
	font=&quot;Tahoma&quot; fontsize=&quot;12&quot;
	query = &quot;GetCourses&quot;&gt;
&lt;/cfgrid&gt;
&lt;/code&gt;

Run that code in ColdFusion 9 or 10 and BOOM!

&lt;p class=&quot;alert-message error&quot;&gt;
Attribute validation error for the CFGRID tag.
&lt;br /&gt;
height/width attribute cannot be a percentage value.
&lt;/p&gt;

Is a percentage value a &quot;valid CSS measurement unit&quot;? Yes it is! Was this a CF8 bug that was fixed in CF9? An oversight in documentation? Either way it&apos;s a PITA.

&lt;h3&gt;Solution&lt;/h3&gt;

I tried redefining the classes on the DIVs that make up the grid, but they all have inline definitions, so those &amp;lt;style&amp;gt; entries get overridden. Then I tried using &lt;a href=&quot;http://jquery.com&quot; class=&quot;outbound&quot; target=&quot;_top&quot;&gt;jQuery&lt;/a&gt; with setTimeout() to replace the inline CSS values after the page has completed loading, to little effect.

&lt;code&gt;&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function(){

	setTimeout( function(){
		$(&apos;div.x-grid-container&apos;).css(&apos;width&apos;, &apos;100%&apos;);
		$(&apos;div.x-grid&apos;).css(&apos;width&apos;, &apos;100%&apos;);
		$(&apos;div.x-grid-topbar&apos;).css(&apos;width&apos;, &apos;100%&apos;);
		$(&apos;div.x-grid-scroller&apos;).css(&apos;width&apos;, &apos;100%&apos;);
		$(&apos;div.x-grid-viewport&apos;).css(&apos;width&apos;, &apos;98%&apos;);
		$(&apos;div.x-grid-bottombar&apos;).css(&apos;width&apos;, &apos;100%&apos;);
	}, 2000);

});
&lt;/script&gt;&lt;/code&gt;

This didn&apos;t affect the width of the column headers (if you set autowidth=&quot;true&quot;, the columns scale to the width of their content and then to the width of the grid container). If you resize the browser, an onResize() function kicks in and the DIVs are reset to their original width.

I&apos;m sure we can replace these grids with something like &lt;a href=&quot;http://datatables.net/&quot; class=&quot;outbound&quot; target=&quot;_top&quot;&gt;DataTables&lt;/a&gt; or a direct implementation of an &lt;a href=&quot;http://dev.sencha.com/deploy/ext-4.0.0/examples/#sample-2&quot; class=&quot;outbound&quot; target=&quot;_top&quot;&gt;Ext JS Grid&lt;/a&gt;, but that would incur a lot of regression testing, so that has to wait.

The solution I implemented was to set the width to a static value and move on. If anyone has figured out a way to get these grids to 100% width, I&apos;d love to hear it.
				</description>
				
				<category>ExtJS</category>
				
				<category>ColdFusion</category>
				
				<category>jQuery</category>
				
				<category>Javascript</category>
				
				<pubDate>Thu, 10 May 2012 19:30:00 -0500</pubDate>
				<guid>http://iknowkungfoo.com/blog/index.cfm/2012/5/10/Upgrading-ColdFusion-CFGRID-has-an-inconsistent-width-attribute</guid>
				
				
			</item>
			
			<item>
				<title>Check All Checkboxes with jQuery - Revisited</title>
				<link>http://iknowkungfoo.com/blog/index.cfm/2012/4/18/Check-All-Checkboxes-with-jQuery--Revisited</link>
				<description>
				
				Nearly 4 years ago, I showed how to &quot;check all checkboxes&quot; using jQuery 1.2.6. In this post, I&apos;m going to show a more advanced, but still simple way to handle checkboxes with jQuery that accounts for changes made as of version 1.6.1. I&apos;ll even answer the bracketed field name question that haunts PHP developers.jQuery version 1.6 introduced a new function, &lt;a href=&quot;http://api.jquery.com/prop/&quot; target=&quot;_top&quot; class=&quot;outbound&quot;&gt;.prop()&lt;/a&gt;, for which changes were also made to the &lt;a href=&quot;http://api.jquery.com/attr/&quot; target=&quot;_top&quot; class=&quot;outbound&quot;&gt;.attr()&lt;/a&gt; function. The changes to .attr() were reverted in version 1.6.1 due to a backlash related to backwards compatibility. Basically, it broke everything that was already using .attr(). You can read the documentation for the full details but it boils down to this:

&lt;ul&gt;
&lt;li&gt;Use .attr() to read the HTML attribute of an element.&lt;/li&gt;
&lt;li&gt;Use .prop() to set and read a property of an element. &quot;Properties generally affect the dynamic state of a DOM element &lt;em&gt;without changing the serialized HTML attribute&lt;/em&gt;.&quot; (emphasis mine)&lt;/li&gt;
&lt;/ul&gt;

Here&apos;s an example, straight from the jQuery site:

&lt;fieldset&gt;
&lt;legend&gt;jQuery .attr() vs. .prop()&lt;/legend&gt;
&lt;table class=&quot;zebra-striped&quot;&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;.attr()&lt;/th&gt;
&lt;th&gt;Proper .prop() usage&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;$(window).attr...&lt;/td&gt;
&lt;td&gt;$(window).prop...&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;$(document).attr...&lt;/td&gt;
&lt;td&gt;$(document).prop...&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;$(&quot;:checkbox&quot;).attr(&quot;checked&quot;, true);&lt;/td&gt;
&lt;td&gt;$(&quot;:checkbox&quot;).prop(&quot;checked&quot;, true);&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;$(&quot;option&quot;).attr(&quot;selected&quot;, true);&lt;/td&gt;
&lt;td&gt;$(&quot;option&quot;).prop(&quot;selected&quot;, true);&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/fieldset&gt;

&lt;a href=&quot;http://iknowkungfoo.com/blog/index.cfm/2008/7/9/Check-All-Checkboxes-with-JQuery&quot;&gt;In my previous post&lt;/a&gt;, I used .attr() and .is() as those were the best available functions at the time.

&lt;fieldset&gt;
&lt;legend&gt;Old and busted&lt;/legend&gt;
&lt;code&gt;
 $(&quot;form#&quot; + id + &quot; INPUT[@name=&quot; + name + &quot;][type=&apos;checkbox&apos;]&quot;).attr(&apos;checked&apos;, false);

$(&apos;#checkAllAuto&apos;).is(&apos;:checked&apos;);
&lt;/code&gt;
&lt;/fieldset&gt;

&lt;h3&gt;Specifications!&lt;/h3&gt;

This post is going to cover the following:

&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;#spec1&quot;&gt;Check and Uncheck all checkboxes related to a particular &quot;check all&quot; checkbox.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#spec2&quot;&gt;Manage the &quot;check all&quot; box&lt;/a&gt;
&lt;ol&gt;&lt;li&gt;Uncheck the &quot;check all&quot; box when a related checkbox is un-checked.&lt;/li&gt;
&lt;li&gt;Select the &quot;check all&quot; box when all related checkboxes are selected.&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#spec3&quot;&gt;Handle the PHP naming convention &amp;lt;input type=&quot;checkbox&quot; &lt;strong&gt;name=&quot;foo[]&quot;&lt;/strong&gt; /&amp;gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

The end goal is to write generic process to handle ALL of the &quot;check all&quot; functionality throughout your application.

The examples in this post should run on any version of jQuery 1.7 or greater. Also, I tend to switch between &quot;check all&quot; and &quot;select all&quot; quite a bit. Deal with it. :)

&lt;h3&gt;Generating the HTML&lt;/h3&gt;

Let&apos;s create a simple column with two columns of checkboxes and a &quot;Select All&quot; checkbox for each column. While this example uses ColdFusion to dynamically generate the HTML, it can be easily translated to PHP, .NET or any other server-side language.

&lt;code&gt;&lt;html&gt;
	&lt;head&gt;
		&lt;script src=&quot;//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js&quot;&gt;&lt;/script&gt;
		&lt;script src=&quot;checkall.js&quot;&gt;&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
		
		&lt;table border=&quot;1&quot;&gt;
			&lt;thead&gt;
				&lt;tr&gt;
					&lt;th&gt;&amp;nbsp;&lt;/th&gt;
					&lt;th&gt;name=&quot;foo&quot;&lt;/th&gt;
					&lt;th&gt;name=&quot;bar&quot;&lt;/th&gt;
				&lt;/tr&gt;
			&lt;/thead&gt;
			&lt;tbody&gt;
				&lt;cfoutput&gt;
					&lt;cfloop from=&quot;0&quot; to=&quot;9&quot; index=&quot;i&quot;&gt;
						&lt;tr&gt;
							&lt;td&gt;#i#&lt;/td&gt;
							&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;foo_#i#&quot; name=&quot;foo&quot; value=&quot;#i#&quot; 
									   data-select-all=&quot;sa_foo&quot; class=&quot;checkme&quot; /&gt;&lt;/td&gt;
							&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;bar_#i#&quot; name=&quot;bar&quot; value=&quot;#i#&quot; 
									   data-select-all=&quot;sa_bar&quot; class=&quot;checkme&quot; /&gt;&lt;/td&gt;
						&lt;/tr&gt;
					&lt;/cfloop&gt;
				&lt;/cfoutput&gt;
			&lt;/tbody&gt;
			&lt;tfoot&gt;
				&lt;tr&gt;
					&lt;td&gt;Select All&lt;/td&gt;
					&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;sa_foo&quot; name=&quot;sa_foo&quot; 
								data-checkbox-name=&quot;foo&quot; class=&quot;selectall&quot; /&gt;&lt;/td&gt;
					&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;sa_bar&quot; name=&quot;sa_bar&quot; 
								data-checkbox-name=&quot;bar&quot; class=&quot;selectall&quot; /&gt;&lt;/td&gt;
				&lt;/tr&gt;
			&lt;/tfoot&gt;
			
		&lt;/table&gt;
		
	&lt;/body&gt;
&lt;/html&gt;&lt;/code&gt;

Here&apos;s the generated table:

&lt;fieldset&gt;&lt;legend&gt;Doing the &quot;check all&quot; thing&lt;/legend&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://iknowkungfoo.com/examples/checkall.js&quot;&gt;&lt;/script&gt;
&lt;table class=&quot;zebra-striped&quot;&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&amp;nbsp;&lt;/th&gt;
&lt;th&gt;name=&quot;foo&quot;&lt;/th&gt;
&lt;th&gt;name=&quot;bar&quot;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;foo_0&quot; name=&quot;foo&quot; value=&quot;0&quot; data-select-all=&quot;sa_foo&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;bar_0&quot; name=&quot;bar&quot; value=&quot;0&quot; data-select-all=&quot;sa_bar&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;foo_1&quot; name=&quot;foo&quot; value=&quot;1&quot; data-select-all=&quot;sa_foo&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;bar_1&quot; name=&quot;bar&quot; value=&quot;1&quot; data-select-all=&quot;sa_bar&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;foo_2&quot; name=&quot;foo&quot; value=&quot;2&quot; data-select-all=&quot;sa_foo&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;bar_2&quot; name=&quot;bar&quot; value=&quot;2&quot; data-select-all=&quot;sa_bar&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;foo_3&quot; name=&quot;foo&quot; value=&quot;3&quot; data-select-all=&quot;sa_foo&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;bar_3&quot; name=&quot;bar&quot; value=&quot;3&quot; data-select-all=&quot;sa_bar&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;foo_4&quot; name=&quot;foo&quot; value=&quot;4&quot; data-select-all=&quot;sa_foo&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;bar_4&quot; name=&quot;bar&quot; value=&quot;4&quot; data-select-all=&quot;sa_bar&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;foo_5&quot; name=&quot;foo&quot; value=&quot;5&quot; data-select-all=&quot;sa_foo&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;bar_5&quot; name=&quot;bar&quot; value=&quot;5&quot; data-select-all=&quot;sa_bar&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;foo_6&quot; name=&quot;foo&quot; value=&quot;6&quot; data-select-all=&quot;sa_foo&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;bar_6&quot; name=&quot;bar&quot; value=&quot;6&quot; data-select-all=&quot;sa_bar&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;foo_7&quot; name=&quot;foo&quot; value=&quot;7&quot; data-select-all=&quot;sa_foo&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;bar_7&quot; name=&quot;bar&quot; value=&quot;7&quot; data-select-all=&quot;sa_bar&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;foo_8&quot; name=&quot;foo&quot; value=&quot;8&quot; data-select-all=&quot;sa_foo&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;bar_8&quot; name=&quot;bar&quot; value=&quot;8&quot; data-select-all=&quot;sa_bar&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;foo_9&quot; name=&quot;foo&quot; value=&quot;9&quot; data-select-all=&quot;sa_foo&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;bar_9&quot; name=&quot;bar&quot; value=&quot;9&quot; data-select-all=&quot;sa_bar&quot; class=&quot;checkme&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;tfoot&gt;
&lt;tr&gt;&lt;td&gt;Select All&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;sa_foo&quot; name=&quot;sa_foo&quot; data-checkbox-name=&quot;foo&quot; class=&quot;selectall&quot;&gt;&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;checkbox&quot; id=&quot;sa_bar&quot; name=&quot;sa_bar&quot; data-checkbox-name=&quot;bar&quot; class=&quot;selectall&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tfoot&gt;
&lt;/table&gt;
&lt;/fieldset&gt;

&lt;h3&gt;Avoid inline event handlers.&lt;/h3&gt;

We all learned to use onclick=&quot;this();&quot; and onchange=&quot;that();&quot; in form fields to call some JavaScript function or other. In my opinion, we should stop doing this when possible. I build a lot of applications where the goal is reuse of code and if you write everything inline, you can&apos;t reuse a group of form fields across multiple forms.

I believe that the rules of how a form functions (and that&apos;s what we&apos;re doing here, writing rules) should be moved to an external JavaScript file. Doing so means that you don&apos;t have to go digging into the final HTML to figure out how a form works. This also lets you reuse groups of fields across multiple forms, but gives you the flexibility to easily change how they function.

*steps off the soapbox*

&lt;h3&gt;&lt;a name=&quot;spec1&quot;&gt;&lt;/a&gt;Specification 1: The &quot;check all&quot; checkbox&lt;/h3&gt;

Let&apos;s take a look at the checkboxes in the name=&quot;foo&quot; column:

&lt;code&gt;&lt;input type=&quot;checkbox&quot; id=&quot;foo_#i#&quot; name=&quot;foo&quot; value=&quot;#i#&quot;  data-select-all=&quot;sa_foo&quot; class=&quot;checkme&quot; /&gt;&lt;/code&gt;

Using &quot;i&quot; as the index of my loop, 

&lt;ol&gt;
&lt;li&gt;Each checkbox has a unique ID.&lt;/ii&gt;
&lt;li&gt;Each has the same NAME.&lt;/li&gt;
&lt;li&gt;The unique ID is tied to the VALUE.&lt;/li&gt;
&lt;li&gt;The related &quot;check all&quot; checkbox is specified using and HTML &quot;data-&quot; attribute. In this case &lt;strong&gt;data-select-all=&quot;sa_foo&quot;.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Every non-&quot;check all&quot; checkbox has the CLASS &quot;checkme&quot;.&lt;/li&gt;
&lt;/ol&gt;

As of jQuery 1.4.3, we can read the value of any &quot;data-&quot; attribute using the function &lt;a href=&quot;http://api.jquery.com/data/&quot; target=&quot;_top&quot; class=&quot;outbound&quot;&gt;.data()&lt;/a&gt;. Yes, &quot;data-&quot; is an HTML5 attribute, but this works for non-HTML5 browsers (although your validator might pitch a fit).

Now here&apos;s the &quot;check all&quot; checkbox for the name=&quot;foo&quot; column:

&lt;code&gt;&lt;input type=&quot;checkbox&quot; id=&quot;sa_foo&quot; name=&quot;sa_foo&quot; data-checkbox-name=&quot;foo&quot; class=&quot;selectall&quot; /&gt;&lt;/code&gt;

If you look at the name=&quot;bar&quot; column, you&apos;ll see the same setup using &quot;bar&quot; instead of &quot;foo&quot;.

&lt;fieldset&gt;
&lt;legend&gt;checkall.js (v1)&lt;/legend&gt;

&lt;code&gt;
$(document).ready(function(){ // 1
	// 2
	$(&apos;:checkbox.selectall&apos;).on(&apos;click&apos;, function(){
		// 3
		$(&apos;:checkbox[name=&apos; + $(this).data(&apos;checkbox-name&apos;) + &apos;]&apos;).prop(&quot;checked&quot;, $(this).prop(&quot;checked&quot;));
		
	});
	
});&lt;/code&gt;

&lt;/fieldset&gt;

This code 

&lt;ol&gt;
&lt;li&gt;Does not run until the document is ready to go ( using $(document).ready(); ).&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Uses the jQuery &quot;:checkbox&quot; selector, restricted to those with the class of &quot;selectall&quot; and adds a CLICK event to them using the jQuery 1.7 &lt;a href=&quot;http://api.jquery.com/on/&quot; target=&quot;_top&quot; class=&quot;outbound&quot;&gt;.on()&lt;/a&gt; function. (Previous to 1.7, you can use .click().)&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;closure&lt;/em&gt; (anonymous function) assigned to the &quot;select all&quot; checkbox
&lt;ol&gt;
&lt;li&gt;Selects all of the &quot;:checkbox&quot; form elements with a NAME matching its &quot;data-checkbox-name&quot; attribute,&lt;/li&gt;
&lt;li&gt;then calls the .prop() function and assigns to each of them the same &quot;checked&quot; property it has.
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;

So if the &quot;check all&quot; checkbox has a property of checked=&quot;true&quot;, then so do all of its related checkboxes. If it&apos;s &quot;false&quot;, they&apos;re all checked=&quot;false&quot;.

&lt;h3&gt;&lt;a name=&quot;spec2&quot;&gt;&lt;/a&gt;Specification 2: Manage the &quot;check all&quot; checkbox.&lt;/h3&gt;

Now that you can check all of the individual checkboxes at once, what happens when one of them is unchecked? The &quot;check all&quot; box should be unchecked too. Also, if all of the individual checkboxes are manually checked, then the &quot;check all&quot; should be checked as well.

By relating the individual checkboxes to the &quot;check all&quot; checkbox using a &quot;data-&quot; attribute, this is also pretty straight forward:

&lt;fieldset&gt;
&lt;legend&gt;checkall.js (v2)&lt;/legend&gt;
&lt;code&gt;
$(document).ready(function(){
	
	$(&apos;:checkbox.selectall&apos;).on(&apos;click&apos;, function(){
		$(&apos;:checkbox[name=&apos; + $(this).data(&apos;checkbox-name&apos;) + &apos;]&apos;).prop(&quot;checked&quot;, $(this).prop(&quot;checked&quot;));
	});
	// Individual checkboxes
	$(&apos;:checkbox.checkme&apos;).on(&apos;click&apos;, function(){ // 1

		var _this = $(this); // 2
		var _selectall = _this.prop(&quot;checked&quot;); //3

		if ( _selectall ) { // 4
			// 5
			$( &apos;:checkbox[name=&apos; + _this.attr(&apos;name&apos;) + &apos;]&apos; ).each(function(i){
				// 6
				_selectall = $(this).prop(&quot;checked&quot;);
				return _selectall; // 7
			});

		}
		
		// 8
		$(&apos;:checkbox[name=&apos; + $(this).data(&apos;select-all&apos;) + &apos;]&apos;).prop(&quot;checked&quot;, _selectall);
	});
	
});
&lt;/code&gt;
&lt;/fieldset&gt;

This code also waits until the document is ready to go. Then, 

&lt;ol&gt;
&lt;li&gt;It uses the jQuery &quot;:checkbox&quot; selector, restricted to those with the class of &quot;checkme&quot; and adds a CLICK event to them using the .on() function.&lt;/li&gt;
&lt;li&gt;Inside the closure, for sake of this example, I&apos;ve created a private variable &quot;_this&quot; equal to $(this), which is a pointer to the current $(&apos;:checkbox&apos;) object.&lt;/li&gt;
&lt;li&gt;Next, create a private variable &quot;_selectall&quot; and assign it the value of the &quot;checked&quot; property (true or false) of the current checkbox.&lt;/li&gt;
&lt;li&gt;If this checkbox has a property of &quot;checked&quot; equal to &lt;strong&gt;true&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;then loop through all checkboxes with the same NAME (using another closure; within this closure, $(this) refers to the $(&apos;:checkbox&apos;) object on the previous line.)&lt;/li&gt;
&lt;li&gt;Set &quot;_selectall&quot; to the &quot;checked&quot; property of the current checkbox.&lt;/li&gt;
&lt;li&gt;By returning &quot;_selectall&quot; (true or false) in each iteration of the .each() loop, if the current individual checkbox has a property of &quot;checked&quot; that is &lt;strong&gt;false&lt;/strong&gt;, we break out of the loop and continue&lt;/li&gt;
&lt;li&gt;Finally, use the value of &quot;data-select-all&quot; in the current &quot;checkme&quot; checkbox to find its related &quot;check all&quot; checkbox and set its &quot;checked&quot; property. If &lt;em&gt;any&lt;/em&gt; or the related individual checkboxes is unchecked, then so should be the &quot;check all&quot; box.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;&lt;a name=&quot;spec3&quot;&gt;&lt;/a&gt;Specification 3: PHP and form field names using brackets.&lt;/h3&gt;

If a form has a group of fields with the same name, when it is submitted, the values of those fields are sent as multiple parameters to the server. For example, if we selected all name=&quot;foo&quot; fields and submitted them to foo.htm using a GET, this is the result:

&lt;code&gt;
foo.htm?foo=0&amp;foo=1&amp;foo=2&amp;foo=3&amp;foo=4&amp;foo=5&amp;foo=6&amp;foo=7&amp;foo=8&amp;foo=9&amp;sa_foo=on
&lt;/code&gt;

If the ACTION on the form was foo.cfm, the query string would be the same, but the ColdFusion parser can reference a URL variable &quot;foo&quot; whose value would be &quot;0,1,2,3,4,5,6,7,8,9&quot;.

Now, if the ACTION was foo.php, the PHP parser would set the value of the variable &quot;foo&quot; to that the &lt;em&gt;last instance&lt;/em&gt; of &quot;foo&quot; in the query string. So in this case, PHP would say that foo = 9.

HOWEVER, if we changed the NAME of the individual checkboxes from name=&quot;foo&quot; to name=&quot;&lt;strong&gt;foo[]&lt;/strong&gt;&quot;, the square brackets tell PHP that foo is an ARRAY with 10 elements in it, ranging from values 0 through 9.

&lt;code&gt;
&lt;input type=&quot;checkbox&quot; id=&quot;foo_#i#&quot; name=&quot;foo[]&quot; value=&quot;#i#&quot; data-select-all=&quot;sa_foo&quot; class=&quot;checkme&quot; /&gt;

&lt;input type=&quot;checkbox&quot; id=&quot;sa_foo&quot; name=&quot;sa_foo&quot; data-checkbox-name=&quot;foo[]&quot; class=&quot;selectall&quot; /&gt;
&lt;/code&gt;

But this causes a problem with JavaScript and in this case jQuery. Defining a jQuery selector using name=&quot;foo[]&quot; causes an error (message from Chrome):

&lt;code&gt;
$(&apos;:checkbox[name=&apos; + $(this).data(&apos;checkbox-name&apos;) + &apos;]&apos;);
&lt;/code&gt;

&lt;p class=&quot;alert-message error&quot;&gt;Uncaught Error: Syntax error, unrecognized expression: [name=foo[]]&lt;/p&gt;

The above code is equivalent to this:

&lt;code&gt;
$(&apos;:checkbox[name=foo[]]&apos;);
&lt;/code&gt;

which throws an &quot;unrecognized expression&quot; error &lt;em&gt;because the JavaScript parser thinks that foo[] is a JavaScript variable of type array which has not yet been defined&lt;/em&gt;.

So this is an easy fix:

&lt;code&gt;
$(&apos;:checkbox[name=&quot;&apos; + $(this).data(&apos;checkbox-name&apos;) + &apos;&quot;]&apos;);
&lt;/code&gt;

can you see that? It&apos;s fixed by &lt;em&gt;using double quotes around your attribute value&lt;/em&gt;. The code is now equivalent to this:

&lt;code&gt;
$(&apos;:checkbox[name=&quot;foo[]&quot;]&apos;);
&lt;/code&gt;

to which the JavaScript parser says (in a very &quot;Alan Rickman as Marvin the Robot&quot; style voice), &quot;Wow. Another string value. How very boring.&quot;

&lt;h3&gt;Final checkall.js&lt;/h3&gt;

Here&apos;s the final version of checkall.js with &quot;_this&quot; and blank lines removed.

&lt;code&gt;
$(document).ready(function(){
	$(&apos;:checkbox.selectall&apos;).on(&apos;click&apos;, function(){
		$(&apos;:checkbox[name=&quot;&apos; + $(this).data(&apos;checkbox-name&apos;) + &apos;&quot;]&apos;).prop(&quot;checked&quot;, $(this).prop(&quot;checked&quot;));
	});
	$(&apos;:checkbox.checkme&apos;).on(&apos;click&apos;, function(){
		var _selectall = $(this).prop(&quot;checked&quot;);
		if ( _selectall ) {
			$( &apos;:checkbox[name=&quot;&apos; + $(this).attr(&apos;name&apos;) + &apos;&quot;]&apos; ).each(function(i){
				_selectall = $(this).prop(&quot;checked&quot;);
				return _selectall;
			});
		}
		$(&apos;:checkbox[name=&quot;&apos; + $(this).data(&apos;select-all&apos;) + &apos;&quot;]&apos;).prop(&quot;checked&quot;, _selectall);
	});
});
&lt;/code&gt;

&lt;h3&gt;In conclusion . . .&lt;/h3&gt;

The &quot;check all&quot; checkbox is a standard user interface widget. It is easy to define similar widgets using jQuery to access standard attributes &amp; properties, along with common (if not yet standard) HTML5-style data attributes, of common elements throughout your application. By defining an application-wide library of widgets, it is possible to shorten your development time lines.

I&apos;ll be posting more jQuery examples soon. If there&apos;s anything you&apos;d like to see, please let me know via the Contact page.
				</description>
				
				<category>ColdFusion</category>
				
				<category>PHP</category>
				
				<category>jQuery</category>
				
				<category>Javascript</category>
				
				<category>HTML5</category>
				
				<pubDate>Wed, 18 Apr 2012 08:00:00 -0500</pubDate>
				<guid>http://iknowkungfoo.com/blog/index.cfm/2012/4/18/Check-All-Checkboxes-with-jQuery--Revisited</guid>
				
				
			</item>
			
			<item>
				<title>Looking for ColdFusion, Java, JavaScript, UI and SQL Developers</title>
				<link>http://iknowkungfoo.com/blog/index.cfm/2012/2/17/Looking-for-ColdFusion-Java-JavaScript-UI-and-SQL-Developers</link>
				<description>
				
				I have been at Equator for 2.5 years, currently a Senior Enterprise Architect and I&apos;m having a blast working here. We have multiple openings in Los Angeles, Irvine, Plano, and Seattle. In addition to developers, we also need Business Analysts and Technical Project Managers. If you&apos;re interested in working with a leader in the Real Estate and Financial Services Industry, please read on.&quot;Equator provides a Platform that automates and connects the Default Servicing industry. Mortgage Lenders, Mortgage Insurers, Servicers, Vendors, Real Estate Professionals and Government Entities use the Platform to automate their daily process and connect to transact in a safe and transparent environment.&quot;

Our application stack (core):

&lt;ul&gt;
&lt;li&gt;ColdFusion 8 on IIS&lt;/li&gt;
&lt;li&gt;ColdBox MVC framework&lt;/li&gt;
&lt;li&gt;jQuery and jQueryUI&lt;/li&gt;
&lt;li&gt;JBoss SOA stack&lt;/li&gt;
&lt;li&gt;SQL Server 2008&lt;/li&gt;
&lt;/ul&gt;

Our offices are located in Los Angeles (headquarters), Irvine (CA), Plano (TX) and we just opened in Seattle (WA). Many of these positions are contract only; telecommuting is available for all full-time employees and for contractors on a case-by-case basis. However, you must be based in California, Texas or Washington.

The following positions are open at any of our offices unless noted otherwise.

For more information and to apply for any position, &lt;a href=&quot;https://www.equator.com/home/index.cfm/company/careers/&quot; class=&quot;outbound&quot; target=&quot;_blank&quot;&gt;visit Equator.com&lt;/a&gt;. On the application form, where it says &quot;Where did you hear about us?&quot;, please put &quot;Adrian Moreno&quot;. :)

&lt;h2&gt;ColdFusion Developers&lt;/h2&gt;

The Developer&apos;s main goal is to implement the application as specified within the planned timeframe. The Developer is also expected to help specify the features of physical design, estimate time and effort to complete each feature, build or supervise implementation of features, prepare product for deployment, and provide technology subject-matter expertise to the team.

Considered a plus: Experience with Java, MVC frameworks and object oriented programming

&lt;h2&gt;Java Developers (LA, Irvine or Dallas)&lt;/h2&gt;

Implements software development projects within planned time frames using Java technologies. Specifies features of physical design, estimates time and effort needed to complete each feature, builds or supervises implementation of features, prepares product for deployment, and provides technology subject matter expertise to the development team.

Considered a plus: Experience with the JBoss SOA stack, Tomcat, Rules Engine, BPM, ESB, Spring, Hibernate and related technologies.

&lt;h2&gt;UI / JavaScript Developers&lt;/h2&gt;

Contribute to the development of Equator&apos;s HTML5 mobile application; Improve website and application usability through the use of AJAX and advanced JavaScript functionality; Establish and maintain HTML/CSS/JS mobile standards documentation; Ensure compliance with best practice coding standards.

We need both a UI Designer and a UI Developer (a.k.a. JavaScript Rock Star).

&lt;h2&gt;SQL Developers&lt;/h2&gt;

These developers will not deal with the administration of SQL Servers. Instead, they will be writing stored procedures and functions to be used by the application developers.

&lt;h2&gt;Business Analyst (Dallas)&lt;/h2&gt;

The Business Analyst works with client to analyze, identify, assess and document business requirements. This role supports internal and external clients with the discovery, approval, specification, creation and testing of projects.

&lt;h2&gt;Technical Project Manager&lt;/h2&gt;

The Project Manager is responsible for effectively managing multiple projects simultaneously, with a focus on launching systems, infrastructure and operational projects. This position will directly support all Equator departments providing project leadership for large, cross-functional, new product and support deployments as well as various special projects, while leveraging existing Equator PMO methodologies and procedures.

&lt;hr /&gt;

Again, for more information and to apply for any position, &lt;a href=&quot;https://www.equator.com/home/index.cfm/company/careers/&quot; class=&quot;outbound&quot; target=&quot;_blank&quot;&gt;visit Equator.com&lt;/a&gt;. On the application form, where it says &quot;Where did you hear about us?&quot;, please put &quot;Adrian Moreno&quot;. :)
&lt;hr /&gt;

&lt;strong&gt;Attention recruiters:&lt;/strong&gt; please don&apos;t contact me about these positions. We&apos;re already working with selected agencies. Thank you.
				</description>
				
				<category>Jobs</category>
				
				<category>SQL</category>
				
				<category>ColdFusion</category>
				
				<category>ColdBox</category>
				
				<category>Java</category>
				
				<category>jQuery</category>
				
				<category>Javascript</category>
				
				<category>HTML5</category>
				
				<pubDate>Fri, 17 Feb 2012 17:53:00 -0500</pubDate>
				<guid>http://iknowkungfoo.com/blog/index.cfm/2012/2/17/Looking-for-ColdFusion-Java-JavaScript-UI-and-SQL-Developers</guid>
				
				
			</item>
			
			<item>
				<title>ColdFusion 10 Beta is here!</title>
				<link>http://iknowkungfoo.com/blog/index.cfm/2012/2/17/ColdFusion-10-Beta-is-here</link>
				<description>
				
				&lt;a href=&quot;http://labs.adobe.com/technologies/coldfusion10/&quot; class=&quot;outbound&quot; target=&quot;_blank&quot;&gt;Go get it!.&lt;/a&gt;
				</description>
				
				<category>ColdFusion</category>
				
				<category>jQuery</category>
				
				<category>OOP</category>
				
				<category>HTML5</category>
				
				<pubDate>Fri, 17 Feb 2012 16:48:00 -0500</pubDate>
				<guid>http://iknowkungfoo.com/blog/index.cfm/2012/2/17/ColdFusion-10-Beta-is-here</guid>
				
				
			</item>
			
			<item>
				<title>D-Flex is hosting Ted Patrick from Sencha Feb 16, 2012</title>
				<link>http://iknowkungfoo.com/blog/index.cfm/2012/2/10/DFlex-is-hosting-Ted-Patrick-from-Sencha-Feb-16-2012</link>
				<description>
				
				The DFW ColdFusion User Group normally meets the 2nd Tuesday of each month. We&apos;d planned to avoid Valentine&apos;s day and meet on the 16th with a 2nd presentation on Ext.js. However, the guys at the Dallas Flex User Group informed me that they will be hosting Ted Patrick from Sencha (the owners of Ext.js) on the same night. Check out the details and note that this is NOT at our normal meeting location at Paladin&apos;s offices.&lt;h2&gt;Special Guest @ D-Flex - Take a look at Sencha with Ted Patrick!&lt;/h2&gt;

&lt;strong&gt;Date and Time:&lt;/strong&gt; February 16, 2012 07:00 PM - 09:00 PM&lt;br /&gt;
Please RSVP @ &lt;a href=&quot;http://groups.adobe.com/index.cfm?event=post.display&amp;postid=40888&quot; class=&quot;outbound&quot; target=&quot;_blank&quot;&gt;D-Flex.org&lt;/a&gt;.

1st Floor Conference Room&lt;br /&gt;
12001 North Central Expressway&lt;br /&gt;
Dallas, TX 75243

Parking is available in the Garage north of the building.&lt;br /&gt;
*** Avoid spaces marked reserved.  

&lt;iframe width=&quot;425&quot; height=&quot;350&quot; frameborder=&quot;0&quot; scrolling=&quot;no&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; src=&quot;http://maps.google.com/maps?q=12001+North+Central+Expressway++Dallas,+TX+75243&amp;amp;ie=UTF8&amp;amp;hq=&amp;amp;hnear=12001+N+Central+Expy,+Dallas,+Texas+75243&amp;amp;t=m&amp;amp;z=14&amp;amp;ll=32.913802,-96.768409&amp;amp;output=embed&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;small&gt;&lt;a href=&quot;http://maps.google.com/maps?q=12001+North+Central+Expressway++Dallas,+TX+75243&amp;amp;ie=UTF8&amp;amp;hq=&amp;amp;hnear=12001+N+Central+Expy,+Dallas,+Texas+75243&amp;amp;t=m&amp;amp;z=14&amp;amp;ll=32.913802,-96.768409&amp;amp;source=embed&quot; style=&quot;color:#0000FF;text-align:left&quot;&gt;View Larger Map&lt;/a&gt;&lt;/small&gt;

&lt;h3&gt;Speaker&lt;/h3&gt;

Ted Patrick currently holds the position of Director of Developer Relations at Sencha. He works with developers to create applications using web technologies including HTML5, JavaScript, and CSS. Prior to Sencha, Ted worked at Barnes and Noble on NOOK Apps and on Flash &amp; Flex at Adobe Systems. Along the way, he founded 4 companies as an entrepreneur, raised vc funding, and sold 1. Ted loves to write software. No, He really, really, loves to write software. So much he can hardly think of it as work. Ted especially loves to help solve the hard strategy problems in combining business and software. The past 2 years have been filled with learning the ins and outs of the Android Operating System and how best to write software for phone-tablet form factor devices (IOS/Android). Lately, Ted dove head first into building apps using HTML5. When he is not writing code, you will find him either spending time with his family or scuba diving.

&lt;h3&gt;Agenda&lt;/h3&gt;

This month we thought we&apos;d take a look at something a little different than our usual. We&apos;ll be welcoming Ted Patrick who will walk you through Sencha&apos;s frameworks for building mobile and desktop applications using web technologies including HTML5, JavaScript, and CSS. We will cover the framework&apos;s foundation (OOP+MVC), standard libraries, containers, components, xtype rendering, and most importantly cross-browser support. Bring an open mind and a laptop, we will be building applications from scratch; feel free to follow along. Sencha provides frameworks, tools, and services for building professional applications with HTML5.

&lt;ul&gt;
&lt;li&gt;7:00pm - 7:15pm : Announcements&lt;/li&gt;
&lt;li&gt;7:15pm - 8:30pm : Hello Sencha: HTML5 Applications&lt;/li&gt;
&lt;li&gt;8:45pm - 9:00pm : Open Question and Answer&lt;/li&gt;
&lt;/ul&gt;

Drinks and meet up afterwards!
				</description>
				
				<category>Sencha</category>
				
				<category>CFUG</category>
				
				<category>Flex</category>
				
				<category>Javascript</category>
				
				<category>HTML5</category>
				
				<pubDate>Fri, 10 Feb 2012 17:34:00 -0500</pubDate>
				<guid>http://iknowkungfoo.com/blog/index.cfm/2012/2/10/DFlex-is-hosting-Ted-Patrick-from-Sencha-Feb-16-2012</guid>
				
				
			</item>
			
			<item>
				<title>OpenCF Summit and ColdBox Training Discount</title>
				<link>http://iknowkungfoo.com/blog/index.cfm/2012/2/10/OpenCF-Summit-and-ColdBox-Training-Discount</link>
				<description>
				
				The first CFML conference of the year is almost here. Come on down to Dallas and hang out with one of the largest ColdFusion / CFML communities in the US.&quot;[The] OpenCF Summit is a community gathering focused exclusively on advancing free and open source software in the CFML community.

If you&apos;re interested in diving into the free software CFML engines,  learning more about the free software movement, and interacting with the most progressive thinkers in the CFML community, OpenCF Summit is for you!&quot; 

&lt;a href=&quot;http://opencfsummit.org&quot; class=&quot;outbound&quot; target=&quot;_blank&quot;&gt;http://opencfsummit.org&lt;/a&gt;

The conference is only $72. If you have the means, I highly recommend checking it out. 

Luis Majano, the author of the ColdBox MVC framework for ColdFusion will be in town and he&apos;s offering a discount for ColdBox Training (training is separate from conference fees). 

&lt;a href=&quot;http://coldbox.eventbrite.com/?discount=awesome&quot; class=&quot;outbound&quot; target=&quot;_blank&quot;&gt;You can register for training here.&lt;/a&gt; Training will be on Feb. 20 and 22, 2012.
				</description>
				
				<category>Conference</category>
				
				<category>Railo</category>
				
				<category>ColdFusion</category>
				
				<category>ColdBox</category>
				
				<category>OpenBD</category>
				
				<pubDate>Fri, 10 Feb 2012 17:22:00 -0500</pubDate>
				<guid>http://iknowkungfoo.com/blog/index.cfm/2012/2/10/OpenCF-Summit-and-ColdBox-Training-Discount</guid>
				
				
			</item>
			
			<item>
				<title>iKnowKungFoo is Evolving</title>
				<link>http://iknowkungfoo.com/blog/index.cfm/2011/11/29/iKnowKungFoo-is-Evolving</link>
				<description>
				
				It&apos;s been a year and a half since my last post and over two years since my last truly technical post. I promised myself I&apos;d get back to writing this year, but life and work kept getting in the way. Fortunately, I&apos;ve been able to get a number of things back on track over the last few months. This blog is one of them.&lt;h2&gt;Blogging in the Cloud&lt;/h2&gt;

My blog is now on a Rackspace Cloud server, running ColdFusion 9 on CentOS 5.5. I basically spun up one of their LAMP images, then consulted &lt;a href=&quot;http://www.aaronwest.net/blog/index.cfm/2011/2/7/Super-Guide-Installing-ColdFusion-9-on-CentOS-Linux&quot; target=&quot;_blank&quot; class=&quot;outbound&quot;&gt;Aaron West&apos;s excellent guide&lt;/a&gt;, made a few adjustments for ColdFusion Standard and was up and running in short order.

&lt;h2&gt;Upgrading BlogCFC&lt;/h2&gt;

Previously, I was running BlogCFC version 5.9.001. There have been a number of upgrades since then related to both security and functionality. I exported the MySQL database from my previous host, then installed the latest version of BlogCFC locally, including the latest MySQL schema.

Thankfully, most columns in the BlogCFC database have default values set. Once I had the newest version of the database, I just ran the INSERT scripts from the MySQL dump file in order to populate the database. After that, I updated the single record in &quot;tblusers&quot;, changing the username to that from my live site.

If you&apos;ve run the blog application before making all of these data changes, you&apos;ll not see your data correctly. Re-initializing the blog application won&apos;t help, you&apos;ll have to restart the CF server. At least, that&apos;s what I had to do.

&lt;h2&gt;Twitter Bootstrap&lt;/h2&gt;

At this year&apos;s Adobe MAX conference, I gave a presentation at the ColdFusion Unconference. The presentation was titled, &quot;Laying the Foundation for Modern ColdFusion Applications&quot;. Really, it continued, &quot;using HTML5, BluePrintCSS, jQuery, jQueryUI, jQuery Validate&quot; and so on, but I only had 50 minutes.

After the presentation, someone (and I apologize for not recalling your name) came up and asked if I&apos;d looked at &lt;a href=&quot;http://twitter.github.com/bootstrap/&quot; class=&quot;outbound&quot; target=&quot;_blank&quot;&gt;Twitter Bootstrap&lt;/a&gt;, &quot;a toolkit from Twitter designed to kickstart development of webapps and sites.&quot; I&apos;d heard of it, but never used it. Until now.

It&apos;s very easy to get started with Twitter Bootstrap if you&apos;re worked with other CSS Grids. Using one of their example layouts, I had the blog styled within a few minutes. Currently, TB is not &quot;reactive&quot;, meaning it doesn&apos;t use CSS Media Queries to re-size itself to whatever device is viewing it. Therefore, you&apos;ll have to switch out layouts programmatically to adjust to smaller displays.

&lt;h2&gt;Moving on up, to HTML5 . . .&lt;/h2&gt;

While I was working on all of this, Adobe made their announcements about focusing on HTML5. I&apos;ve been working with the &lt;a href=&quot;http://html5boilerplate.com/&quot; class=&quot;outbound&quot; target=&quot;_blank&quot;&gt;HTML5BoilerPlate&lt;/a&gt; as a template for some other recent applications, so i decided to integrate pieces of it with Twitter Bootstrap in order to create my modern application foundation.

I was given a review copy of &lt;a href=&quot;http://www.manning.com/crowther/&quot; class=&quot;outbound&quot; target=&quot;_blank&quot;&gt;Hello! HTML5 and CSS3&lt;/a&gt; by Rob Crowther from Manning Publishing a few months ago. I&apos;ll post a detailed review shortly, but I&apos;ll say now that after a quick read-through, it was a breeze to pick up on the parallels between how we&apos;ve traditionally laid out HTML4 vs HTML5.

&lt;h2&gt;Evolution&lt;/h2&gt;

I&apos;ve got a couple of years&apos; worth of blog posts rattling around in my head as well as a few books. If there&apos;s anything you&apos;d like me to cover, please use the Contact form and I&apos;ll do my best to respond quickly.

If you happen to see anything odd with the layout, please send me a note and include which browser you&apos;re using. I only tested this layout in Chrome, FireFox 3.6.x and MSIE 9.

During a Fishbowl session at the ColdFusion Unconference this year, &lt;a href=&quot;http://www.boyzoid.com/blog/&quot; class=&quot;outbound&quot; target=&quot;_blank&quot;&gt;Scott Stroz&lt;/a&gt; brought up the fact that as developers, we need to constantly &lt;strong&gt;evolve&lt;/strong&gt;. I couldn&apos;t agree more.

I have been very fortunate to have worked in a wide range of industries. At each employer, I&apos;ve learned concepts which I then applied as needed at subsequent employers. This has allowed me to evolve and, I hope, help others evolve. By getting this blog back up and running, I hope to do both again.
				</description>
				
				<category>ColdFusion</category>
				
				<category>Blog Info</category>
				
				<category>HTML5</category>
				
				<category>Adobe MAX</category>
				
				<pubDate>Tue, 29 Nov 2011 00:57:00 -0500</pubDate>
				<guid>http://iknowkungfoo.com/blog/index.cfm/2011/11/29/iKnowKungFoo-is-Evolving</guid>
				
				
			</item>
			
			<item>
				<title>Adobe ColdFusion Anthology - a new ColdFusion book!</title>
				<link>http://iknowkungfoo.com/blog/index.cfm/2010/5/3/Adobe-ColdFusion-Anthology--a-new-ColdFusion-book</link>
				<description>
				
				Thanks to Michael and Judith Dinowitz, there is a new ColdFusion book on the market, &lt;a href=&quot;http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155&quot; target=&quot;_blank&quot; class=&quot;outbound&quot;&gt;Adobe ColdFusion Anthology&lt;/a&gt;, and I&apos;m glad to have had a hand in it.

I&apos;ve been sitting on this for over a year now it&apos;s finally here! The book is an anthology of articles from &lt;a href=&quot;http://www.fusionauthority.com/&quot; target=&quot;_blank&quot; class=&quot;outbound&quot;&gt;Fusion Authority&lt;/a&gt; magazine. Chapter 11 of the book is my contribution, &quot;You Might Have a Performance Bottleneck If&quot;. Written in the mood of Jeff Foxworthy, I outline 12 common problems in web applications (not just CF applications) that can be easily solved by the proper use of a database.

What are you waiting for? Pick up your copy of &lt;a href=&quot;http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155&quot; target=&quot;_blank&quot; class=&quot;outbound&quot;&gt;Adobe ColdFusion Anthology&lt;/a&gt; today! :)
				</description>
				
				<category>SQL</category>
				
				<category>ColdFusion</category>
				
				<category>Woo-hoo!</category>
				
				<category>Books</category>
				
				<pubDate>Mon, 03 May 2010 14:21:00 -0500</pubDate>
				<guid>http://iknowkungfoo.com/blog/index.cfm/2010/5/3/Adobe-ColdFusion-Anthology--a-new-ColdFusion-book</guid>
				
				
			</item>
			
			<item>
				<title>DFW CFUG presents Head First Design Patterns for ColdFusion</title>
				<link>http://iknowkungfoo.com/blog/index.cfm/2010/3/9/DFW-CFUG-presents-Head-First-Design-Patterns-for-ColdFusion</link>
				<description>
				
				The &lt;a href=&quot;http://www.dfwcfug.org/&quot; target=&quot;_blank&quot; class=&quot;outbound&quot;&gt;Dallas/Ft. Worth ColdFusion User Group&lt;/a&gt; has been working through the book &lt;a href=&quot;http://www.amazon.com/First-Design-Patterns-Elisabeth-Freeman/dp/0596007124/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1265772363&amp;sr=8-1&quot; target=&quot;_blank&quot; class=&quot;outbound&quot;&gt;Head First Design Patterns&lt;/a&gt;, taking the Java-centric code examples in the chapters and implementing them in ColdFusion to see how they may apply to us as ColdFusion developers. &lt;a href=&quot;http://www.dfwcfug.org/blog/2010/02/09/Recording-list-for-Head-First-Design-Patterns-for-CFML-presentations&quot; target=&quot;_blank&quot; class=&quot;outbound&quot;&gt;Click here&lt;/a&gt; for a continually updated list of presentations.

Keep updated with ColdFusion in the DFW area by following &lt;a class=&quot;outbound&quot; target=&quot;_blank&quot; href=&quot;http://twitter.com/dfwcfug&quot;&gt;@dfwcfug&lt;/a&gt; on Twitter.
				</description>
				
				<category>CFUG</category>
				
				<category>ColdFusion</category>
				
				<category>Design Patterns</category>
				
				<category>OOP</category>
				
				<pubDate>Tue, 09 Mar 2010 14:09:00 -0500</pubDate>
				<guid>http://iknowkungfoo.com/blog/index.cfm/2010/3/9/DFW-CFUG-presents-Head-First-Design-Patterns-for-ColdFusion</guid>
				
				
			</item>
			
			<item>
				<title>Special DFW CFUG ColdFusion Builder event March 24th</title>
				<link>http://iknowkungfoo.com/blog/index.cfm/2010/3/9/Special-DFW-CFUG-ColdFusion-Builder-event-March-24th</link>
				<description>
				
				The Dallas / Fort Worth ColdFusion User Group is proud to announce that Adobe Evangelist Terry Ryan will be making &lt;a href=&quot;http://www.dfwcfug.org/blog/2010/03/04/Adobe-Evangelist-Terry-Ryan-in-Dallas--ColdFusion-Builder-Presentation&quot; target=&quot;_blank&quot; class=&quot;outbound&quot;&gt;a special stop in Dallas on March 24th&lt;/a&gt; to present ColdFusion Builder, the new eclipse based IDE for developing ColdFusion applications.PLEASE RSVP ASAP!!! at &lt;a href=&quot;http://groups.adobe.com/posts/a1d79161c4&quot; target=&quot;_blank&quot; class=&quot;outbound&quot;&gt;http://groups.adobe.com/posts/a1d79161c4&lt;/a&gt;. The location is TBD based on RSVP numbers, but will either be in the Paladin offices or another venue in the same building.

Keep updated with ColdFusion in the DFW area by following &lt;a class=&quot;outbound&quot; target=&quot;_blank&quot; href=&quot;http://twitter.com/dfwcfug&quot;&gt;@dfwcfug&lt;/a&gt; on Twitter.
				</description>
				
				<category>CFEclipse</category>
				
				<category>CFUG</category>
				
				<category>ColdFusion</category>
				
				<category>Eclipse</category>
				
				<pubDate>Tue, 09 Mar 2010 13:59:00 -0500</pubDate>
				<guid>http://iknowkungfoo.com/blog/index.cfm/2010/3/9/Special-DFW-CFUG-ColdFusion-Builder-event-March-24th</guid>
				
				
			</item>
			
			<item>
				<title>Presenting The Template Pattern at the DFW CFUG tonight</title>
				<link>http://iknowkungfoo.com/blog/index.cfm/2010/3/9/Presenting-The-Template-Pattern-at-the-DFW-CFUG-tonight</link>
				<description>
				
				Tonight at the &lt;a href=&quot;http://www.dfwcfug.org/blog/2010/03/03/March-Monthly-Meeting-The-Template-Pattern--Head-First-Design-Patterns-for-CF-Ch-8&quot; target=&quot;_blank&quot; class=&quot;oubound&quot;&gt;Dallas/Fort Worth ColdFusion User Group meeting&lt;/a&gt;, I&apos;ll be continuing our series on design patterns with a presentation on The Template Pattern. The meeting will be begin at 6:30 with a training topic. The main presentation will be presented using Adobe Connect, so you can join us live or view the recording later. Keep updated with ColdFusion in the DFW area by following &lt;a href=&quot;http://twitter.com/dfwcfug&quot; target=&quot;_blank&quot; class=&quot;outbound&quot;&gt;@dfwcfug&lt;/a&gt; on Twitter.
				</description>
				
				<category>CFUG</category>
				
				<category>ColdFusion</category>
				
				<category>Design Patterns</category>
				
				<category>OOP</category>
				
				<pubDate>Tue, 09 Mar 2010 13:49:00 -0500</pubDate>
				<guid>http://iknowkungfoo.com/blog/index.cfm/2010/3/9/Presenting-The-Template-Pattern-at-the-DFW-CFUG-tonight</guid>
				
				
			</item>
			
			<item>
				<title>FAQU 3.2 is out! The Things You Didn&apos;t Know You Needed to Know</title>
				<link>http://iknowkungfoo.com/blog/index.cfm/2009/12/17/FAQU-32-is-out-The-Things-You-Didnt-Know-You-Needed-to-Know</link>
				<description>
				
				Sorry I&apos;ve been off the radar for so long, but I&apos;ve had a heck of a year. I&apos;ll be posting a few things shortly, but in the meantime you can take a look at what started out as a blog post and ended up as a published article. My article, &quot;You Might Have a Performance Bottleneck If . . .&quot; has just been published in the latest Fusion Authority Quarterly Update. Yes, you read that correctly. &lt;a href=&quot;http://www.fusionauthority.com/quarterly/&quot; target=&quot;outbound&quot;&gt;There&apos;s a new FAQU and you can read it right now.&lt;/a&gt;
				</description>
				
				<category>SQL</category>
				
				<category>ColdFusion</category>
				
				<category>Woo-hoo!</category>
				
				<pubDate>Thu, 17 Dec 2009 13:22:00 -0500</pubDate>
				<guid>http://iknowkungfoo.com/blog/index.cfm/2009/12/17/FAQU-32-is-out-The-Things-You-Didnt-Know-You-Needed-to-Know</guid>
				
				
			</item>
			
			<item>
				<title>Screwy issue when defining a string. (cfif within a cfset)</title>
				<link>http://iknowkungfoo.com/blog/index.cfm/2009/3/13/Screwy-issue-when-defining-a-string-cfif-within-a-cfset</link>
				<description>
				
				I was browsing through some tickets in Jira today when I found a couple of bugs related to tables not displaying correctly in MSIE. When I found an example, it basically looked like a &amp;lt;TR&amp;gt; tag had not been closed correctly. When I viewed the source HTML, imagine how surprised I was to find a &amp;lt;cfif&amp;gt; statement gumming up the works.&lt;h2&gt;Disclaimer&lt;/h2&gt;

I inherited this code.

&lt;h2&gt;The Problem&lt;/h2&gt;

The report I was looking at pulls from a few different tables, including a Notes table. Some notes are entered manually and others are automatically created by the system. When I checked the table, I found quite a few notes that contained the same &lt;cfif&gt; statement.

&lt;h2&gt;The Code&lt;/h2&gt;

This is the line of code in question:

&lt;fieldset&gt;&lt;legend&gt;Let&apos;s make a string&lt;/legend&gt;
&lt;code&gt;
&lt;cfset foo = structNew() /&gt;
&lt;cfset str = &quot;&quot; /&gt;

&lt;cfset foo.firstName = &quot;Adrian&quot; /&gt;
&lt;cfset foo.lastName = &quot;Moreno&quot; /&gt;
&lt;cfset foo.phone = &quot;5551234567&quot; /&gt;
&lt;cfset foo.fax = &quot;5551234568&quot; /&gt;

&lt;cfset str = str &amp; &quot;#foo.firstName# #foo.lastName# [&lt;cfif foo.phone NEQ &quot;&quot;&gt;(#Left(foo.phone,3)#) #Mid(foo.phone,4,3)#-#Mid(foo.phone,7,4)# | &lt;/cfif&gt;(#Left(foo.fax,3)#) #Mid(foo.fax,4,3)#-#Mid(foo.fax,7,4)# (f)]&quot;&gt;
&lt;/code&gt;
&lt;/fieldset&gt;

The actual code gets data from a query, not a struct, but the effect is the same. If you were to render this CFML, you&apos;d get this output:

&lt;fieldset&gt;
&lt;legend&gt;&amp;lt;cfoutput&amp;gt;&lt;/legend&gt;
&lt;strong&gt;Firefox:&lt;/strong&gt;

&lt;code&gt;Adrian Moreno [(555) 123-4567 | (555) 123-4568 (f)]&lt;/code&gt;

&lt;strong&gt;MSIE:&lt;/strong&gt;

&lt;code&gt;Adrian Moreno [&lt;cfif foo.phone NEQ &quot;&gt;(555) 123-4567 | (555) 123-4568 (f)]&lt;/code&gt;
&lt;/fieldset&gt;

If you do a View Source, you&apos;ll see that the actual rendered value of the CFML variable &lt;strong&gt;str&lt;/strong&gt; is: 

&lt;fieldset&gt;&lt;legend&gt;Picture Kyle&apos;s mom going, &quot;What, what, what?!?&quot;&lt;/legend&gt;
&lt;code&gt;Adrian Moreno [&lt;cfif foo.phone NEQ &quot;&gt;(555) 123-4567 | &lt;/cfif&gt;(555) 123-4568 (f)]&lt;/code&gt;
&lt;/fieldset&gt;

&lt;h2&gt;WTF?&lt;/h2&gt;

It&apos;s this string that&apos;s stored in the Notes table. MSIE is getting to &amp;lt;/cfif&amp;gt; and then pitches a fit. Firefox doesn&apos;t know what a CFIF tag is, so it just skips over it and displays the text alone.

If you&apos;ll notice, the opening cfif tag was checking if foo.phone was an empty string:

&lt;code&gt;&lt;cfif foo.phone NEQ &quot;&quot;&gt;&lt;/code&gt;

but the rendered string only has the one double quote:

&lt;code&gt;&lt;cfif foo.phone NEQ &quot;&gt;&lt;/code&gt;

So why didn&apos;t ColdFusion throw an error here?

&lt;h2&gt;Testing&lt;/h2&gt;

Let&apos;s create another string that doesn&apos;t contain any CF variables:

&lt;code&gt;
&lt;cfset strb = &quot;Hello there my name is not an empty string &quot;&quot; it&apos;s Adrian.&quot; /&gt;

&lt;cfoutput&gt;#strb#&lt;/cfoutput&gt;
&lt;/code&gt;

And the output:

&lt;code&gt;Hello there my name is not an empty string &quot; it&apos;s Adrian. &lt;/code&gt;

Ok, that makes sense. The outer double quotes define the string, so any pair of double quotes next to each other like this are replaced with a single double quote, which is the expected functionality.

So maybe losing the pair of double quotes within the CFIF tag causes ColdFusion to skip over parsing it?

Let&apos;s change the original code to use single quotes in the CFIF:

&lt;code&gt;
&lt;cfset str = str &amp; &quot;#foo.firstName# #foo.lastName# [&lt;cfif foo.phone NEQ &apos;&apos;&gt;(#Left(foo.phone,3)#) #Mid(foo.phone,4,3)#-#Mid(foo.phone,7,4)# | &lt;/cfif&gt;(#Left(foo.fax,3)#) #Mid(foo.fax,4,3)#-#Mid(foo.fax,7,4)# (f)]&quot;&gt;
&lt;/code&gt;

And the rendered HTML source: 

&lt;code&gt;Adrian Moreno [&lt;cfif foo.phone NEQ &apos;&apos;&gt;(555) 123-4567 | &lt;/cfif&gt;(555) 123-4568 (f)]&lt;/code&gt;

Allllllllrighty then.

&lt;h2&gt;Conclusion&lt;/h2&gt;

I think it&apos;s safe to say that ColdFusion can parse variables within a string definition, but it won&apos;t parse tags. In order to get the intended output from this code, it needs to be updated like this:

&lt;code&gt;
&lt;cfset str = str &amp; &quot;#foo.firstName# #foo.lastName# [&quot; /&gt;
&lt;cfif foo.phone NEQ &quot;&quot;&gt;
	&lt;cfset str = str &amp; &quot;(#Left(foo.phone,3)#) #Mid(foo.phone,4,3)#-#Mid(foo.phone,7,4)# | &quot; /&gt;
&lt;/cfif&gt;
&lt;cfset str = str &amp; &quot;(#Left(foo.fax,3)#) #Mid(foo.fax,4,3)#-#Mid(foo.fax,7,4)# (f)]&quot; /&gt;
&lt;/code&gt;

Rendered HTML source:

&lt;code&gt;Adrian Moreno [(555) 123-4567 | (555) 123-4568 (f)]&lt;/code&gt;

In conclusion, I think this shows that you can&apos;t just write your code and assume it will work as expected, &lt;strong&gt;&lt;em&gt;even when no errors are thrown&lt;/em&gt;&lt;/strong&gt;. Test, test and again test your output to make sure it&apos;s correct.

Now if you&apos;ll excuse me, I have to go update ~3 years of records in that table. &lt;img src=&quot;/images/smileys/bangHead.gif&quot; /&gt;
				</description>
				
				<category>ColdFusion</category>
				
				<category>WTF</category>
				
				<pubDate>Fri, 13 Mar 2009 17:51:00 -0500</pubDate>
				<guid>http://iknowkungfoo.com/blog/index.cfm/2009/3/13/Screwy-issue-when-defining-a-string-cfif-within-a-cfset</guid>
				
				
			</item>
			
			<item>
				<title>SQL approach to Showing Every Nth Record</title>
				<link>http://iknowkungfoo.com/blog/index.cfm/2009/2/20/SQL-approach-to-Showing-Every-Nth-Record</link>
				<description>
				
				Earlier today, Ray Camden posted a quick ColdFusion-centric solution to &lt;a class=&quot;outbound&quot; target=&quot;_blank&quot; href=&quot;http://www.coldfusionjedi.com/index.cfm/2009/2/20/Ask-a-Jedi-Showing-Every-Nth-Record&quot;&gt;showing only the Nth records&lt;/a&gt; of a query. His solution is fine, but I wonder how it would perform for large queries on a site under high load. Here&apos;s a database-centric solution that pulls back every Nth record, allowing CF to just display the final record set.&lt;strong&gt;This example uses SQL Server 2005.&lt;/strong&gt;

&lt;h3&gt;Step 1&lt;/h3&gt;

There&apos;s a table in the database named &quot;Districts&quot;. Let&apos;s get all the Districts for Texas.

&lt;code&gt;
SELECT 
	Name
FROM 
	Districts 
WHERE 
	state = &apos;TX&apos; 
ORDER BY 
	Name
&lt;/code&gt;

This brings back 1,063 rows. 

&lt;img src=&quot;/images/blog/sql_mod_results_00.jpg&quot; /&gt;

&lt;h3&gt;Step 2&lt;/h3&gt;

Let&apos;s use the ROW_NUMBER() function to get a record count within the results.

&lt;code&gt;
SELECT 
	Name,
	ROW_NUMBER() OVER ( ORDER BY Name ) AS &apos;RowNumber&apos;
FROM 
	Districts 
WHERE 
	state = &apos;TX&apos; 
&lt;/code&gt;

Notice that the ORDER BY clause is no longer needed at the end of the query. It&apos;s now called from within ROW_NUMBER(). We still have 1,063 records, but now we can start manipulating the results.

&lt;img src=&quot;/images/blog/sql_mod_results_01.jpg&quot; /&gt;

&lt;h3&gt;Step 3&lt;/h3&gt;

We&apos;ll go ahead and select * from the results we just returned (now aliased as EXPR1), but we&apos;ll also get the MOD of each &lt;strong&gt;RowNumber&lt;/strong&gt; using 5 as the divisor.

&lt;code&gt;
SELECT 
	Name, 
	RowNumber,
	(EXPR1.RowNumber % 5) AS ROW_MOD
FROM
	(
	SELECT 
		Name,
		ROW_NUMBER() OVER ( ORDER BY Name ) AS &apos;RowNumber&apos;
	FROM 
		Districts 
	WHERE 
		state = &apos;TX&apos; 
	) EXPR1
&lt;/code&gt;

Still 1,063 rows, but we&apos;re getting close.

&lt;img src=&quot;/images/blog/sql_mod_results_02.jpg&quot; /&gt;

&lt;h3&gt;Step 4&lt;/h3&gt;

Now we just select * from the last record set (aliased as EXPR2) WHERE ROW_MOD = 0 and we&apos;re done.

&lt;code&gt;
SELECT 
	EXPR2.*
FROM 
	(
	SELECT 
		Name, 
		RowNumber,
		(EXPR1.RowNumber % 5) AS ROW_MOD
	FROM
		(
		SELECT 
			Name,
			ROW_NUMBER() OVER ( ORDER BY Name ) AS &apos;RowNumber&apos;
		FROM 
			Districts 
		WHERE 
			state = &apos;TX&apos; 
		) EXPR1
	) EXPR2
WHERE 
	EXPR2.ROW_MOD = 0
&lt;/code&gt;

&lt;img src=&quot;/images/blog/sql_mod_results_03.jpg&quot; /&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;

The final result? 212 records where RowNumber MOD 5 = 0. This is every 5th row of the original query. 

&lt;strong&gt;Traditional ColdFusion approach:&lt;/strong&gt; Bring back 1,063 records from the database, then either (a, cfoutput) iterate over the entire record set, checking if the currentrow MOD 5 = 0 or (b, cfloop) iterate over the entire record set, stepping by 5.

&lt;strong&gt;ColdFusion with smart SQL approach:&lt;/strong&gt; Bring back the 212 records we need and display them.

I know which way I prefer. :)

&lt;h3&gt;Related Links&lt;/h3&gt;

Jules Gravinese has posted how to &lt;a target=&quot;_blank&quot; class=&quot;outbound&quot; href=&quot;http://www.webveteran.com/blog/index.php/web-coding/mysql/mysql-select-every-nth-record/&quot;&gt;Select Every Nth Record with MySQL&lt;/a&gt;.
				</description>
				
				<category>SQL</category>
				
				<category>ColdFusion</category>
				
				<pubDate>Fri, 20 Feb 2009 13:19:00 -0500</pubDate>
				<guid>http://iknowkungfoo.com/blog/index.cfm/2009/2/20/SQL-approach-to-Showing-Every-Nth-Record</guid>
				
				
			</item>
			</channel></rss>
