<?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>Blog of Shaun McCran - Architecting robust, elegant technical and business solutions - Json</title>
			<link>http://www.mccran.co.uk/index.cfm</link>
			<description>I write about Architecture and Design, Architectural patterns, Architectural Principles and Architectural policies. This includes TOGAF, Zachman, Business Architecture, SOA and Process and tools such as the IBM Rational software and Adobe products. I also write about my previous life as a mobile and web developer.</description>
			<language>en-gb</language>
			<pubDate>Tue, 09 Jun 2026 06:56:54 -0000</pubDate>
			<lastBuildDate>Sun, 26 Sep 2010 19:05:00 -0000</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>shaun@mccran.co.uk</managingEditor>
			<webMaster>shaun@mccran.co.uk</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>shaun@mccran.co.uk</itunes:email>
				<itunes:name></itunes:name>
			</itunes:owner>
			
			<itunes:explicit>no</itunes:explicit>
			
			
			
			
			
			<item>
				<title>JQuery AJAX Http polling example</title>
				<link>http://www.mccran.co.uk/index.cfm/2010/9/26/JQuery-AJAX-Http-polling-example</link>
				<description>
				
				I&apos;ve been using the JQuery post() and get() functions for a while now, and thanks to decent Blog entries from other community members I&apos;ve got my head around the principles of seamless AJAX http requests and response handling.
&lt;p&gt;
This article examines a way of creating a polling AJAX http request. This is a request that will run every &lt;i&gt;N&lt;/i&gt; seconds based on a value. It will hit a remote service and return a result, and display that result on screen.
&lt;p&gt;
View a full demo of an &lt;a href=&quot;http://www.mccran.co.uk/examples/jquery-polling/index.cfm&quot; target=&quot;_blank&quot;&gt;AJAX polling request here.&lt;/a&gt;
&lt;p&gt;
				 [More]
				</description>
				
				
				<category>JQuery</category>
				
				<category>Coldfusion</category>
				
				<category>Json</category>
				
				<category>AJAX</category>
				
				<pubDate>Sun, 26 Sep 2010 19:05:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2010/9/26/JQuery-AJAX-Http-polling-example</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Cross site AJAX HttpRequest problems and how to create a Proxy handler</title>
				<link>http://www.mccran.co.uk/index.cfm/2010/7/19/Cross-site-AJAX-HttpRequest-problems-and-how-to-create-a-Proxy-handler</link>
				<description>
				
				Most of us are familiar with the AJAX post() and getJSON() methods of remotely calling and passing around data, I use them with abundance when building applications. One thing I had not considered until recently is that all my AJAX Http requests are usually internal to that application, which also means they are on the same server and domain.

I recently jumped into a project where the application spanned 24 domains, and had been developed to use a core component library to help code re use. The problem with this arose when you are on one domain (www.domain1.com) and you want to make a request to a different domain (www.domain2.com). You encounter something called the &apos;same-Origin&apos; policy.

This article deals with how to create a proxy to handle cross site AJAX http Requests.
				 [More]
				</description>
				
				
				<category>JQuery</category>
				
				<category>Coldfusion</category>
				
				<category>Json</category>
				
				<category>AJAX</category>
				
				<pubDate>Mon, 19 Jul 2010 15:36:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2010/7/19/Cross-site-AJAX-HttpRequest-problems-and-how-to-create-a-Proxy-handler</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>JQuery Datatables plugin example using a server side data request (coldfusion)</title>
				<link>http://www.mccran.co.uk/index.cfm/2010/4/29/JQuery-Datatables-plugin-example-using-a-server-side-data-request-coldfusion</link>
				<description>
				
				Im my previous article on how to use the JQuery datatables plug I concentrated mainly on the JQuery script, and how to build the AJAX request to receive a JSON response. 

In this article I will demonstrate the full application which will include the front end JQuery, building the back end server response and a few tips that I&apos;ve picked up since implementing the plugin. I am using an MS SQL table filled with UK location data that I also used for a weather webservice, to fill the table.

A full example of this working can be seen here: &lt;a href=http://www.mccran.co.uk/examples/datatable/index.cfm target=_blank&gt;Data table server side example&lt;/a&gt;
				 [More]
				</description>
				
				
				<category>JQuery</category>
				
				<category>Coldfusion</category>
				
				<category>Javascript</category>
				
				<category>RIA</category>
				
				<category>Json</category>
				
				<category>AJAX</category>
				
				<pubDate>Thu, 29 Apr 2010 18:04:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2010/4/29/JQuery-Datatables-plugin-example-using-a-server-side-data-request-coldfusion</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>What does &quot;Invalid Label&quot; mean in a JSON response, and how can I fix it?</title>
				<link>http://www.mccran.co.uk/index.cfm/2010/3/23/What-does-Invalid-Label-mean-in-a-JSON-response-and-how-can-I-fix-it</link>
				<description>
				
				I recently build an application that returned a JSON object of data based on a select field value. Whilst I was building this I encountered an error using the JavaScript eval() function on my JSON response. I am using the eval() function to parse a string from my JSON response, but firebug is showing a JavaScript error of &quot;Invalid Label&quot;.

This is the code:

&lt;code&gt;

function(data){
	jsonResponse = eval(data);
	var src = jsonResponse.DATA;
	});
&lt;/code&gt;

After having a Google around it appears that the eval function is interpreting the first item in the JSON response as a label, rather than data. By changing the code like this:

&lt;code&gt;
jsonResponse = eval(&quot;(&quot; + data + &quot;)&quot;);
&lt;/code&gt;

We are forcing eval to recognise the data as variable data. Now the JSON to string translation works.
				
				</description>
				
				
				<category>JQuery</category>
				
				<category>Javascript</category>
				
				<category>Json</category>
				
				<category>AJAX</category>
				
				<pubDate>Tue, 23 Mar 2010 14:36:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2010/3/23/What-does-Invalid-Label-mean-in-a-JSON-response-and-how-can-I-fix-it</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Creating an image preview using JQuery and a select form field</title>
				<link>http://www.mccran.co.uk/index.cfm/2010/3/22/Creating-an-image-preview-using-JQuery-and-a-select-form-field</link>
				<description>
				
				This article will deal with a user choosing a value from a Select field, and that selection being passed to a JQuery handler. The JQuery handler will perform an AJAX request to a CFC, which will return a JSON value (URL String) that we will use to populate an img html tag.

In this way when you select different options from the select field drop down, the image changes inline, without any page reloads.
				 [More]
				</description>
				
				
				<category>JQuery</category>
				
				<category>Coldfusion</category>
				
				<category>RIA</category>
				
				<category>Json</category>
				
				<pubDate>Mon, 22 Mar 2010 14:56:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2010/3/22/Creating-an-image-preview-using-JQuery-and-a-select-form-field</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Using other plug-ins with the JQuery Carousel Plug-in and event issues</title>
				<link>http://www.mccran.co.uk/index.cfm/2010/3/15/Using-other-plugins-with-the-JQuery-Carousel-Plugin-and-event-issues</link>
				<description>
				
				This entry examines how the JQuery Carousel object interacts with other Plug-ins, and how to combine those plug-ins with the Carousel functionality.  I also cover an issue where the jCarousel plug-in does not apply functionality to non visible elements when the page loads.
				 [More]
				</description>
				
				
				<category>JQuery</category>
				
				<category>RIA</category>
				
				<category>Json</category>
				
				<category>AJAX</category>
				
				<pubDate>Mon, 15 Mar 2010 15:24:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2010/3/15/Using-other-plugins-with-the-JQuery-Carousel-Plugin-and-event-issues</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Using the JQuery dataTables plugin to display dynamic data in tables: part 1</title>
				<link>http://www.mccran.co.uk/index.cfm/2010/2/25/Using-the-JQuery-dataTables-plugin-to-display-dynamic-data-in-tables-part-1</link>
				<description>
				
				Rather than writing out long winded table code to display your data in a tabulated fashion why not use the dataTables JQuery plugin to do it for you?

In this blog entry I&apos;ll be generating tables using a JQuery plugin, but I will also be generating the JQuery code from an XML document.

The theory behind the dataTables JQuery plugin is that when the template loads it makes an AJAX request to a remotely specified template. That template returns a JSON object of data which is formatted and used in a tabular display. This means that you can perfom filtering and sort functions inline, and the JQuery simply re submits the AJAX request, receiving new JSON each time. So no refreshing.

I&apos;ll be dealing with the auto generation of the JSON back end in the second part of this article. Here is how I setup the tabular display.

Build a standard html template, including the CSS and JQuery plugins.

&lt;code&gt;

&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &quot;http://www.w3.org/TR/html4/transitional.dtd&quot;&gt;
&lt;html lang=&quot;en-GB&quot;&gt;
&lt;head&gt;
&lt;InvalidTag http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; lang=&quot;en&quot;&gt;
&lt;InvalidTag name=&quot;language&quot; content=&quot;en-GB&quot;&gt;

&lt;style type=&quot;text/css&quot; title=&quot;currentStyle&quot;&gt; 
	@import &quot;demo_page.css&quot;;
	@import &quot;demo_table.css&quot;;
&lt;/style&gt;

&lt;s/cript type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;s/cript type=&quot;text/javascript&quot; language=&quot;javascript&quot; src=&quot;jquery.dataTables.js&quot;&gt;&lt;/script&gt; 

&lt;/code&gt;

Next we build our JQuery function. I wont go into massive detail about all the parameters and values being passed in here, but it is well documented on &lt;a href= http://www.datatables.net/ target=_blank&gt; http://www.datatables.net/&lt;/a&gt;.

&lt;code&gt;

&lt;s/cript type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;
$(document).ready(function() {
				$(&apos;#example&apos;).dataTable( {
					&quot;bProcessing&quot;: true,
					&quot;bServerSide&quot;: true,
					&quot;sAjaxSource&quot;: &quot;content.cfm&quot;,
					&quot;aoColumns&quot;: [
{ &quot;sName&quot;: &quot;Edit&quot;, &quot;sTitle&quot;: &quot;Edit&quot;, &quot;sWidth&quot;:&quot;10%&quot;} ,
{ &quot;sName&quot;: &quot;Band&quot;, &quot;sTitle&quot;: &quot;Band&quot;} ,
{ &quot;sName&quot;: &quot;Genre&quot;,&quot;sTitle&quot;: &quot;Genre&quot;} ,
{ &quot;sTitle&quot;: &quot;Fake Column&quot;} 
],
					&quot;sPaginationType&quot;: &quot;full_numbers&quot;,
					&quot;aaSorting&quot;: [[1,&apos;asc&apos;]],
					&quot;oLanguage&quot;: {
						&quot;sLengthMenu&quot;: &quot;Page length: _MENU_&quot;,
						&quot;sSearch&quot;: &quot;Filter:&quot;
					}
				} );
			} );
&lt;/script&gt;

&lt;/code&gt;

The really important column here is the &quot;aoColumns&quot; JSON data block. This specifies what fields are returned from your AJAX call, and parameters they must adhere to.

In this example we are anticipating that we will receive four columns of data back (Edit,Band,Genre and Fake Column).

Lastly we create a table with an ID of &quot;example&quot;, as this is what the JQuery is looking for. This table must be formatted in a certain way, as the JQuery plugin will re write the specified elements.


&lt;code&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; border=&quot;0&quot; class=&quot;display&quot; id=&quot;example&quot;&gt; 
&lt;thead&gt;
&lt;tr&gt;
   &lt;th&gt;Edit&lt;/th&gt;
   &lt;th&gt;Band&lt;/th&gt;
   &lt;th&gt;Genre&lt;/th&gt;
  &lt;th&gt;Fake Column&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
   &lt;tbody&gt;
   &lt;tr&gt;
       &lt;td colspan=&quot;3&quot; class=&quot;dataTables_empty&quot;&gt;Loading data from server&lt;/td&gt; 
   &lt;/tr&gt;
   &lt;/tbody&gt;
&lt;/table&gt;
&lt;/code&gt;

The code also contains the header elements that will match the returned column values from the AJAX request. The last part of the table is displayed when the data is loading.

This all works well, but to extend it further I have altered the code to read from an XML document. The XML document Is loaded when the template starts, and the data fields and attributes are read, and looped over to create the JQuery code and table headers. In this way it is a generic table display template, driven from an XML document.

The XML doc:

&lt;code&gt;

&lt;?xml version=&quot;1.0&quot;?&gt;
   &lt;form&gt;
      &lt;field sName=&quot;Edit&quot; source=&quot;data&quot; sTitle=&quot;Edit&quot; sWidth=&quot;10%&quot;&gt;Edit&lt;/field&gt;
      &lt;field sName=&quot;Band&quot; source=&quot;data&quot; sTitle=&quot;Band&quot;&gt;Band&lt;/field&gt;
      &lt;field sName=&quot;Genre&quot; source=&quot;data&quot; sTitle=&quot;Genre&quot;&gt;Genre&lt;/field&gt;
      &lt;field sName=&quot;fake column&quot; source=&quot;&quot; sTitle=&quot;Fake Column&quot;&gt;Fake column&lt;/field&gt;
   &lt;/form&gt;
&lt;/code&gt;

Read the XML file and parse it out into an Array:

&lt;code&gt;
&lt;!--- parse the xml file ---&gt;
&lt;cfset variables.xml = XMLParse(&quot;test.xml&quot;) /&gt;
&lt;!--- &lt;cfdump var=&quot;#variables.xml#&quot; label=&quot;Raw xml document&quot;&gt; ---&gt;
&lt;cfset variables.fields = XMLSearch(variables.xml,&quot;form/field&quot;)&gt;
&lt;cfset variables.totalRecords = ArrayLen(variables.fields)&gt;
&lt;/code&gt;

Use something like this to dynamically generate the JQuery and table values:

&lt;code&gt;
&lt;cfoutput&gt;
&lt;cfloop index=&quot;variables.index&quot; from=&quot;1&quot; to=&quot;#ArrayLen(variables.fields)#&quot;&gt;
   { &lt;cfif variables.fields[variables.index].XmlAttributes.source EQ &quot;data&quot;&gt;&quot;sName&quot;: &quot;#variables.fields[variables.index].XmlAttributes.sName#&quot;,&lt;/cfif&gt;
    &lt;cfif structkeyexists(variables.fields[variables.index].XmlAttributes, &apos;sTitle&apos;)&gt;&quot;sTitle&quot;: &quot;#variables.fields[variables.index].XmlAttributes.sTitle#&quot;&lt;/cfif&gt;
   &lt;cfif structkeyexists(variables.fields[variables.index].XmlAttributes, &apos;sWidth&apos;)&gt;,&quot;sWidth&quot;:&quot;#variables.fields[variables.index].XmlAttributes.sWidth#&quot;&lt;/cfif&gt;
   } &lt;cfif variables.index NEQ variables.totalRecords&gt;,&lt;/cfif&gt;
&lt;/cfloop&gt;
&lt;/cfoutput&gt;
&lt;!--- table values ---&gt;

&lt;cfoutput&gt;
  &lt;cfloop index=&quot;variables.index&quot; from=&quot;1&quot; to=&quot;#ArrayLen(variables.fields)#&quot;&gt;
    &lt;th align=&quot;left&quot;&gt;#variables.fields[variables.index].XmlText#&lt;/th&gt; 
  &lt;/cfloop&gt;
&lt;/cfoutput&gt;
&lt;/code&gt;

The JSON response is hard coded in this example, so the result will not filter or search. I&apos;ll handle that in article two.

There is a full example of this &lt;a href=http://www.mccran.co.uk/examples/datatables/ target=_blank&gt;here&lt;/a&gt;.
				
				</description>
				
				
				<category>JQuery</category>
				
				<category>Coldfusion</category>
				
				<category>RIA</category>
				
				<category>Json</category>
				
				<category>AJAX</category>
				
				<pubDate>Thu, 25 Feb 2010 12:26:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2010/2/25/Using-the-JQuery-dataTables-plugin-to-display-dynamic-data-in-tables-part-1</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Connecting Select form fields based on data selections Pt 3</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/8/20/Connecting-Select-form-fields-based-on-data-selections-Pt-3</link>
				<description>
				
				I&apos;ve been exploring various methods of using JQuery to populate Select form fields. In the previous article I used an intermediary file to act as a handler for the JSON returned object. In this last article I have removed the extra handler template, interfacing directly with the CFC.

Firstly there are some small changes to the JQuery url call.

&lt;code&gt;
&lt;scr/ipt src=&quot;jquery-1.2.3.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;scr/ipt src=&quot;select-chain.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;scr/ipt type=&quot;text/javascript&quot;&gt;
   jQuery.noConflict();
   jQuery(function () {
    var type = jQuery(&apos;#series&apos;);
    var sp = jQuery(&apos;#issueno&apos;);
    var selectedSeries = jQuery(&apos;#series&apos;).val();

    type.selectChain({
    target: sp,
    url: &apos;jquerySeries.cfc?method=getIssueNos&apos;,
       type: &apos;post&apos;,
    data: { ajax: true, returnformat: &apos;plain&apos;, series: selectedSeries }
    }).trigger(&apos;change&apos;);

   });
&lt;/script&gt;
&lt;/code&gt;

Now we are directly referencing the CFC. Simply append the function name as a url parameter. In the &quot;DATA&quot; element we place the data we are passing in the form of key value pairs. This will build all the values into the JQuery url, so the final URL would be:

&lt;code&gt;
jquerySeries.cfc?method=getIssueNos&amp;ajax=true&amp;returnformat=plain&amp;series=selectedSeries
&lt;/code&gt;

At this point I was getting an parse error, until I found the &apos;returnFormat&apos; value. Coldfusion will return WDDX encoded packets by default, problem was my handler was looking for Json. Adding this value will stop this.

Next we have the same form as before, there are no changes at all: (here for completeness really)

&lt;code&gt;
  &lt;cfset variables.series = createObject(&quot;component&quot;,&quot;jquerySeries&quot;).getSeries()&gt;
   &lt;form action=&quot;&quot; method=&quot;post&quot;&gt;
      &lt;select name=&quot;series&quot; id=&quot;series&quot;&gt;
         &lt;cfoutput query=&quot;variables.series&quot;&gt;
         &lt;option value=&quot;#variables.series.intId#&quot;&gt;#variables.series.varName#&lt;/option&gt;
         &lt;/cfoutput&gt;
      &lt;/select&gt;
      &lt;select name=&quot;issueno&quot; id=&quot;issueno&quot;&gt;
         &lt;option&gt;&lt;/option&gt;
      &lt;/select&gt;
      &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;
   &lt;/form&gt;
&lt;/code&gt;

Lastly there are one or two small changes to our CFC function.

&lt;code&gt;
	&lt;cffunction name=&quot;getIssueNos&quot; access=&quot;remote&quot; output=&quot;false&quot; hint=&quot;returns related series issue numbers&quot;&gt;
		&lt;cfargument name=&quot;series&quot; type=&quot;numeric&quot; required=&quot;false&quot; hint=&quot;Id of the publication&quot;&gt;
		&lt;cfset var result = &quot;&quot;&gt;

		&lt;cfquery name=&quot;result&quot; datasource=&quot;#application.ds#&quot;&gt;
			SELECT [intIssueNo]
			FROM [dbo].[tbl_cn_series_issueNos]
			where intSeriesId = &lt;cfqueryparam value=&quot;#arguments.series#&quot; cfsqltype=&quot;cf_sql_integer&quot;&gt;
		&lt;/cfquery&gt;
		
		&lt;cfsetting showdebugoutput=&quot;false&quot;&gt;
		&lt;cfset ojson = createObject(&quot;component&quot;,&quot;cfjson&quot;)&gt;
		&lt;cfset theresults = ojson.encode(listToArray(valuelist(result.intIssueNo)))&gt;
		&lt;cfsetting enablecfoutputonly=&quot;true&quot;&gt;
	&lt;cfreturn theresults&gt;
	&lt;/cffunction&gt;
&lt;/code&gt;

The access method has changed, so we add an &quot;access=remote&quot; value to expose the function as a service. Then we serialize the query result into JSON, and return it. This seems like a much more succinct way of doing this.
				
				</description>
				
				
				<category>Coldfusion</category>
				
				<category>Javascript</category>
				
				<category>RIA</category>
				
				<category>Json</category>
				
				<category>AJAX</category>
				
				<pubDate>Thu, 20 Aug 2009 10:10:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/8/20/Connecting-Select-form-fields-based-on-data-selections-Pt-3</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Connecting Select form fields based on data selections Pt 2</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/8/18/Connecting-Select-form-fields-based-on-data-selections-Pt-2</link>
				<description>
				
				I want to be able to dynamically change a second select field based on the value of the first select field.

Following on from the cfajaxproxy example I wrote last week, where I discovered I could not use ColdFusion 8 functionality on my live server, I have arrived at a variant solution.

In this example I am using a similar JQuery url request to process the output from a CFC. The first template is the form itself. This includes references to the JQuery libraries and the binding of the response to the form elements. It also builds the url request to the &apos;request_processor.cfm&apos; file, which handles the CFC. 

&lt;code&gt;
&lt;scr/ipt src=&quot;jquery-1.2.3.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;scr/ipt src=&quot;select-chain.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;scr/ipt type=&quot;text/javascript&quot;&gt;
   jQuery.noConflict();
   jQuery(function () {
    var type = jQuery(&apos;#series&apos;);
    var sp = jQuery(&apos;#issueno&apos;);

    type.selectChain({
    target: sp,
    url: &apos;request_processor.cfm&apos;,
       type: &apos;post&apos;,
    data: { ajax: true }
    }).trigger(&apos;change&apos;);

   });
&lt;/script&gt;

&lt;/code&gt;

Next build a simple form, and populate the first select field with data from a method.

&lt;code&gt;

&lt;cfif not structisempty(form)&gt;
   &lt;cfdump var=&quot;#form#&quot;&gt;
&lt;cfelse&gt;
   &lt;cfset variables.series = createObject(&quot;component&quot;,&quot;jquerySeries&quot;). getSeries()&gt;
   &lt;form action=&quot;&quot; method=&quot;post&quot;&gt;
      &lt;select name=&quot;series&quot; id=&quot;series&quot;&gt;
         &lt;cfoutput query=&quot;variables.series&quot;&gt;
         &lt;option value=&quot;#variables.series.intId#&quot;&gt;#variables.series.varName#&lt;/option&gt;
         &lt;/cfoutput&gt;
      &lt;/select&gt;
      &lt;select name=&quot;issueno&quot; id=&quot;issueno&quot;&gt;
         &lt;option&gt;&lt;/option&gt;
      &lt;/select&gt;
      &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;
   &lt;/form&gt;
&lt;/cfif&gt;
&lt;/code&gt;

Next is the intermediately file that handles the data manipulation, this is triggered when the user chooses an option from the first select field. It passes through the selected value, and returns the query object. This is then serialised using the cfJson object, to return the data in Json. If you do anything like this remember to watch your debug output, it was destroying my Json response for a good ten minutes before I remembered to turn it off. Doh!

&lt;code&gt;
&lt;cfsetting showdebugoutput=&quot;false&quot;&gt;
&lt;cfsetting enablecfoutputonly=&quot;true&quot;&gt;
&lt;cfparam name=&quot;form.series&quot; default=&quot;8&quot;&gt;
&lt;cfset variables.issues = createObject(&quot;component&quot;,&quot;jquerySeries&quot;).getIssueNos(series=form.series)&gt;
&lt;cfset ojson = createObject(&quot;component&quot;,&quot;cfjson&quot;)&gt;
&lt;cfset theresults = ojson.encode(listToArray(valuelist(variables.issues.intIssueNo)))&gt;
&lt;cfoutput&gt;#theresults#&lt;/cfoutput&gt;

&lt;/code&gt;

Finally a CFC that performs the database functions. This is a pretty straight forward CFC that performs two database queries, the second based on an id passed in from the first.

&lt;code&gt;
&lt;cfcomponent&gt;

	&lt;cffunction name=&quot;getSeries&quot; output=&quot;false&quot; hint=&quot;Returns publication series&quot;&gt;
		&lt;cfset var result = &quot;&quot;&gt;

	&lt;cfquery name=&quot;result&quot; datasource=&quot;#application.ds#&quot;&gt;
		SELECT [intId],[varName]
		FROM [dbo].[table]
		Where intActive = &apos;1&apos;
		Order by varName
	&lt;/cfquery&gt;

	&lt;cfreturn result&gt;
	&lt;/cffunction&gt;

	&lt;cffunction name=&quot;getIssueNos&quot; output=&quot;false&quot; hint=&quot;returns related series issue numbers&quot;&gt;
		&lt;cfargument name=&quot;series&quot; type=&quot;numeric&quot; required=&quot;false&quot; hint=&quot;Id of the publication&quot;&gt;
		&lt;cfset var result = &quot;&quot;&gt;

		&lt;cfquery name=&quot;result&quot; datasource=&quot;#application.ds#&quot;&gt;
			SELECT [intIssueNo]
			FROM [dbo].[table]
			where intSeriesId = &lt;cfqueryparam value=&quot;#arguments.series#&quot; cfsqltype=&quot;cf_sql_integer&quot;&gt;
		&lt;/cfquery&gt;

	&lt;cfreturn result&gt;
	&lt;/cffunction&gt;
&lt;/cfcomponent&gt;
&lt;/code&gt;

Once you have these elements hooked up you&apos;ll see that the response from the first select field changes the values in the second field. You can download a rar&apos;d version of the code base &lt;a href=&quot;http://www.mccran.co.uk/selectExample.rar&quot; target=&quot;new&quot;&gt;here&lt;/a&gt;.

This works well, but I&apos;m not massively happy about the &apos;remote_processor&apos; file. I think I&apos;ll see if there is a way of directly calling the CFC, and moving the JSON serialisation into the functions.
				
				</description>
				
				
				<category>Coldfusion</category>
				
				<category>Javascript</category>
				
				<category>RIA</category>
				
				<category>Json</category>
				
				<category>AJAX</category>
				
				<pubDate>Tue, 18 Aug 2009 10:15:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/8/18/Connecting-Select-form-fields-based-on-data-selections-Pt-2</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Connecting Select form fields based on data selections Pt 1</title>
				<link>http://www.mccran.co.uk/index.cfm/2009/8/10/Connecting-Select-form-fields-based-on-data-selections-Pt-1</link>
				<description>
				
				Whilst building a new form I discovered that I needed two select fields, one that contained a series of publication titles, and the second that contained the Issue numbers of whatever title was selected in the first field.

IE two selects, with the first controlling the seconds data.

I had a search around and it seems like there are many ways to do this, this by far seems to be the best, but it has a fatal flaw (detailed at the end).

Start off by creating a function call to setup your initial state. This will set the default value of the first select field, and populate the second field with its options.

&lt;code&gt;
&lt;body&gt;
&lt;!--- Set the default Series ---&gt;
&lt;cfset defaultSeries = 7&gt;

&lt;scri pt type=&quot;text/javascript&quot;&gt;
var done = false;
function SelectDefault(x,val) {
 if(!done) {
  var dd = document.getElementById(&apos;intId&apos;);
  for(var i = 0; i &lt; dd.length; i++){
   if(dd.options[i].value == val){
    dd.selectedIndex = i;
   }
  }
  done = true;
 }
}
&lt;/scri pt&gt;
&lt;/code&gt;

Next create the form, and use the cfajaxproxy to bind the default values set above.

The form itself is a pair of cfselects, with the values bound to the response from a CFC (Series). I really like the way the notation works with this, the cfc:&lt;i&gt;Name&lt;/i&gt; . function is really intuitive.

Notice how the binding on the second cfselect is passing through the value from the first &apos;intId&apos; in this example. This is the argument passed to the CFC.

&lt;code&gt;
&lt;!--- Proxy function ---&gt;
&lt;cfajaxproxy bind=&quot;javascript:SelectDefault({intId},#defaultSeries#)&quot;&gt;
 
&lt;cfform name=&quot;exampleform&quot; method=&quot;post&quot;&gt;

&lt;cfselect name=&quot;intId&quot; id=&quot;intId&quot; value=&quot;intId&quot; display=&quot;varName&quot; bindonload=&quot;true&quot; bind=&quot;cfc:Series.GetIssues()&quot;/&gt;
&lt;cfselect name=&quot;issueNo&quot; id=&quot;issueNo&quot; value=&quot;intIssueNo&quot; display=&quot;intIssueNo&quot; bind=&quot;cfc:Series.GetIssueNos({intId})&quot;/&gt;
&lt;cfinput type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot;/&gt;
&lt;/cfform&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;/code&gt;

So that is our form. The next code block is the CFC. It is a relatively straight forward CFC with two functions, each returning a list of data. The second requires an argument passed in from the cfselect above.

&lt;code&gt;
&lt;cfcomponent output=&quot;false&quot;&gt;
	&lt;cffunction name=&quot;GetIssues&quot; access=&quot;remote&quot; returntype=&quot;query&quot;&gt;

		&lt;cfquery name=&quot;data&quot; datasource=&quot;#application.dsn#&quot;&gt;
			SELECT [intId],[varName],			
FROM [dbo].table
			Order by varName
		&lt;/cfquery&gt;

		&lt;cfreturn data&gt;
	&lt;/cffunction&gt;

	&lt;cffunction name=&quot;GetIssueNos&quot; access=&quot;remote&quot; returntype=&quot;query&quot;&gt;
		&lt;cfargument name=&quot;intId&quot;&gt;
        &lt;cfquery name=&quot;data&quot; datasource=&quot;#application.dsn#&quot;&gt;
			SELECT [intIssueNo]
			FROM [dbo].table
			where intSeriesId = &lt;cfqueryparam value=&quot;#arguments.intId#&quot; cfsqltype=&quot;cf_sql_integer&quot;&gt;
     	&lt;/cfquery&gt;
		&lt;cfreturn data&gt;

	&lt;/cffunction&gt;

&lt;/cfcomponent&gt;

&lt;/code&gt;

This just returns two different query objects. When this is all hooked up it works fantastically. Changing the first select changes the issue numbers in the second select.

My problem lies in the fact that this is all ColdFusion 8 functionality. Both cfajaxproxy and cfselect are coldfusion server version 8 tags. My hosting company is still using version 7! Which I discovered when I rolled this code out. (doh!)

So I have to find another solution, which follows shortly.

N.B. Thanks to several of Ben Forta and Ben Nadel&apos;s blog posts around similar subjects for guidance on this, they got me over a few stumbling blocks.
				
				</description>
				
				
				<category>Coldfusion</category>
				
				<category>Javascript</category>
				
				<category>RIA</category>
				
				<category>Json</category>
				
				<category>AJAX</category>
				
				<pubDate>Mon, 10 Aug 2009 14:10:00 -0000</pubDate>
				<guid>http://www.mccran.co.uk/index.cfm/2009/8/10/Connecting-Select-form-fields-based-on-data-selections-Pt-1</guid>
				
				
			</item>
			
		 	
			</channel></rss>