Question

Chained select box using Ajax, ColdFusion and DB

Asked by: panosms

Hello experts.
I have found a working solution on this page:http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/Cold_Fusion_Markup_Language/Q_23902796.html?sfQueryTermInfo=1+ajax+chain+coldfus+select
The question i have is how to make this work using a DB (MSSQL) with two tables parents and children and not a file getChildren.cfm like the example.
(
Below is the code

select.cfm:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body{
	background-repeat:no-repeat;
	font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif;
	height:100%;
	background-color: #FFF;
	margin:0px;
	padding:0px;
}
select{
	width:150px;
}
</style>
<script type="text/javascript">
/* Simple AJAX Code-Kit (SACK) v1.6.1 */
/* ©2005 Gregory Wild-Smith */
/* www.twilightuniverse.com */
/* Software licenced under a modified X11 licence,
   see documentation or authors website for more details */
 
function sack(file) {
	this.xmlhttp = null;
 
	this.resetData = function() {
		this.method = "POST";
  		this.queryStringSeparator = "?";
		this.argumentSeparator = "&";
		this.URLString = "";
		this.encodeURIString = true;
  		this.execute = false;
  		this.element = null;
		this.elementObj = null;
		this.requestFile = file;
		this.vars = new Object();
		this.responseStatus = new Array(2);
  	};
 
	this.resetFunctions = function() {
  		this.onLoading = function() { };
  		this.onLoaded = function() { };
  		this.onInteractive = function() { };
  		this.onCompletion = function() { };
  		this.onError = function() { };
		this.onFail = function() { };
	};
 
	this.reset = function() {
		this.resetFunctions();
		this.resetData();
	};
 
	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}
 
		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	};
 
	this.setVar = function(name, value){
		this.vars[name] = Array(value, false);
	};
 
	this.encVar = function(name, value, returnvars) {
		if (true == returnvars) {
			return Array(encodeURIComponent(name), encodeURIComponent(value));
		} else {
			this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
		}
	}
 
	this.processURLString = function(string, encode) {
		encoded = encodeURIComponent(this.argumentSeparator);
		regexp = new RegExp(this.argumentSeparator + "|" + encoded);
		varArray = string.split(regexp);
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split("=");
			if (true == encode){
				this.encVar(urlVars[0], urlVars[1]);
			} else {
				this.setVar(urlVars[0], urlVars[1]);
			}
		}
	}
 
	this.createURLString = function(urlstring) {
		if (this.encodeURIString && this.URLString.length) {
			this.processURLString(this.URLString, true);
		}
 
		if (urlstring) {
			if (this.URLString.length) {
				this.URLString += this.argumentSeparator + urlstring;
			} else {
				this.URLString = urlstring;
			}
		}
 
		// prevents caching of URLString
		this.setVar("rndval", new Date().getTime());
 
		urlstringtemp = new Array();
		for (key in this.vars) {
			if (false == this.vars[key][1] && true == this.encodeURIString) {
				encoded = this.encVar(key, this.vars[key][0], true);
				delete this.vars[key];
				this.vars[encoded[0]] = Array(encoded[1], true);
				key = encoded[0];
			}
 
			urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
		}
		if (urlstring){
			this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
		} else {
			this.URLString += urlstringtemp.join(this.argumentSeparator);
		}
	}
 
	this.runResponse = function() {
		eval(this.response);
	}
 
	this.runAJAX = function(urlstring) {
		if (this.failed) {
			this.onFail();
		} else {
			this.createURLString(urlstring);
			if (this.element) {
				this.elementObj = document.getElementById(this.element);
			}
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
					} catch (e) { }
				}
 
				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							self.onLoaded();
							break;
 
						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;
 
							if (self.execute) {
								self.runResponse();
							}
 
							if (self.elementObj) {
								elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input"
								|| elemNodeName == "select"
								|| elemNodeName == "option"
								|| elemNodeName == "textarea") {
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							if (self.responseStatus[0] == "200") {
								self.onCompletion();
							} else {
								self.onError();
							}
 
							self.URLString = "";
							break;
					}
				};
 
				this.xmlhttp.send(this.URLString);
			}
		}
	};
 
	this.reset();
	this.createAJAX();
}
 
</script>
<script type="text/javascript">
/************************************************************************************************************
Ajax chained select
Copyright (C) 2006  DTHMLGoodies.com, Alf Magne Kalleland
 
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
 
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.
 
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
Dhtmlgoodies.com., hereby disclaims all copyright interest in this script
written by Alf Magne Kalleland.
 
Alf Magne Kalleland, 2006
Owner of DHTMLgoodies.com
 
 
************************************************************************************************************/	
var ajax = new Array();
 
function getChildrenList(sel)
        {
                var parentCode = sel.options[sel.selectedIndex].value;
                document.getElementById('dhtml_children').options.length = 0;   // Empty city select box
                if(parentCode.length>0){
                        var index = ajax.length;
                        ajax[index] = new sack();
                        ajax[index].requestFile = 'getChildren.cfm?parentCode='+parentCode;     // Specifying which file to get
                        ajax[index].onCompletion = function(){ createChildren(index) }; // Specify function that will be executed after file has been found
                        ajax[index].runAJAX();          // Execute AJAX function
                }
        }
        
        function createChildren(index)
        {
                var obj = document.getElementById('dhtml_children');
                eval(ajax[index].response);     // Executing the response from Ajax as Javascript code  
        }	
</script>
 
</head>
 
<body>
<form action="" method="post">
<table>
        <tr>
                <td>Parent: </td>
                <td><select id="dhtml_parents" name="dhtml_parents" onchange="getChildrenList(this)">
                        <option value="">Select a parent item</option>
                        <option value="p1">Parent 1</option>
                        <option value="p2">Parent 2</option>
                        <option value="p3">Parent 3</option>
                </select>
                </td>
        </tr>
        <tr>
                <td>Children: </td>
                <td>
                <select id="dhtml_children" name="dhtml_children">
                
                        </select>
                </td>
        </tr>
</table>
</form>
 
</body>
</html>
 
getChildren.cfm:
<cfswitch expression="#parentCode#">
        <cfcase value="p1">     
          obj.options[obj.options.length] = new Option('Child 1','1');
          obj.options[obj.options.length] = new Option('Child 2','2');
          obj.options[obj.options.length] = new Option('Child 3','3');
          obj.options[obj.options.length] = new Option('Child 4','4');
                </cfcase>
                
        <cfcase value="p2">  
          obj.options[obj.options.length] = new Option('Child 5','11');
          obj.options[obj.options.length] = new Option('Child 6','12');
          obj.options[obj.options.length] = new Option('Child 7','13');     
                </cfcase>
                
        <cfcase value="p3">  
          obj.options[obj.options.length] = new Option('Child 8','21');
          obj.options[obj.options.length] = new Option('Child 9','22');
          obj.options[obj.options.length] = new Option('Child 10','23');
          obj.options[obj.options.length] = new Option('Child 11','24');
          obj.options[obj.options.length] = new Option('Child 12','25');
          obj.options[obj.options.length] = new Option('Child 13','26');
          obj.options[obj.options.length] = new Option('Child 14','27');
                </cfcase>
                
    <cfdefaultcase>
       
    </cfdefaultcase>
</cfswitch>

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-01-07 at 03:40:49ID24031056
Topics

ColdFusion Application Server

,

Asynchronous Javascript and XML (AJAX)

Participating Experts
2
Points
500
Comments
6

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. What is Cold Fusion
    I am new to this section. What is cold fusion? Where can I learn more about it?
  2. Cold Fusion
    What is Cold Fusion?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: micropc1Posted on 2009-01-08 at 09:44:15ID: 23327541

What about just using a <cfquery> tag in getChildren.cfm?

 

by: panosmsPosted on 2009-01-08 at 10:02:09ID: 23327794

Hi micropc1
Please can you giveme more details?

 

by: DADITWebGroupPosted on 2009-01-12 at 18:54:07ID: 23359670

Are you asking to "bind" two select statements together?  If so, here are some detailed instructions (sorry so long)...

<!--- Add Page code: --->
<!--- First Select - 
** calls out the cfc in bind parameter (filepath and filename are separated by periods as you do in the component parameter in a cfinvoke and then you also add in the function name and a set of empty parenthesis); 
** bindonload set to true; 
** value set to value to pass to action and binding query; 
** display value that is to show up in the dropdown list. --->
<cfselect name="firstselectname" bind="cfc:cfcfilepath.cfcfilename.cfcfirstfunctionname()" bindonload="true" value="ID_value" display="display_value" />
 
<!--- Second Select - 
** calls out the cfc in bind parameter (filepath and filename are separated by periods as you do in the component parameter in a cfinvoke and then you also add in the function name); 
** place the first CFSelect's name in curly brackets inside the parenthesis; 
** value set to value to pass to action and binding query; 
** display value that is to show up in the dropdown list. --->
<cfselect name="secondselectname" bind="cfc:cfcfilepath.cfcfilename.cfcsecondfunctionname({firstselectname})" value="Sub_ID_value" display="Sub_display_value" />
 
<!--- Edit page code: --->
<!--- First Select - 
** calls out the cfc in bind parameter (filepath and filename are separated by periods as you do in the component parameter in a cfinvoke and then you also add in the function name); 
** place fieldname from query that sends pre-selected value to cfc argument (SELECTEDID);
** bindonload set to true; 
** value set to value to pass to action and binding query; 
** display value that is to show up in the dropdown list. --->
<cfselect name="firstselectname" bind="cfc:cfcfilepath.cfcfilename.cfcfirstfunctionname(#qryName.SelectedID#)" bindonload="true" value="ID_value" display="display_value" />
 
<!--- Second Select - 
** calls out the cfc in bind parameter (filepath and filename are separated by periods as you do in the component parameter in a cfinvoke and then you also add in the function name); 
** place the first CFSelect's name in curly brackets inside the parenthesis and place fieldname from query that sends pre-selected value to cfc argument (SELECTEDSUBID) separated by a comma and no spaces and MUST be in the same order as you list them as arguments in the CFC; 
** value set to value to pass to action and binding query; 
** display value that is to show up in the dropdown list. --->
<cfselect name="secondselectname" bind="cfc:cfcfilepath.cfcfilename.cfcsecondfunctionname({firstselectname},#qryName.SelectedSubID#)" value="Sub_ID_value" display="Sub_display_value" />
 
<!--- CFC that takes care of both: --->
<!--- set output to no --->
<cfcomponent output="no">
<!--- First function sets up values for your first CFSelect statement; set access to remote; returntype in this case is array --->
<cffunction name="cfcfirstfuntionname" access="remote" returntype="array" hint="first select list - send selectedid if coming from edit page">
<!--- if call is coming from an edit page where a value was already pre-selected, it will be passed here --->
<cfargument name="selectedid" default="" required="no">
<!--- Define variables and clears them ---> 
<cfset var qrySelectedID=""> 
<cfset var qryListWBind=""> 
<cfset var arList="">
<!--- if call from edit page, query to single out pre-selected values --->
<cfif isDefined("arguments.selectedid") and arguments.selectedid neq "">
<cfquery name="qrySelectedID" datasource="#datasource#">
SELECT ID_value, display_value
FROM table_with_first_values
WHERE ID_value = #arguments.selectedid#
</cfquery>
</cfif>
<!--- Define values for your array to place in first select--->
<!--- if call from edit page, eliminate pre-selected values from the rest of the values with cfif statement in where clause --->
<cfquery name="qryListWBind" datasource="#datasource#">
SELECT ID_value, display_value
FROM table_with_first_values
WHERE <cfif isDefined("arguments.selectedid") and arguments.selectedid neq ""> AND ID_value != #arguments.selectedid#</cfif>
ORDER BY    display_value
</cfquery>
<!--- Build array for first select. If editing, lists the preselected values first. --->
<cfset arList = arraynew(2)>
<cfif isDefined("arguments.selectedid") and arguments.selectedid neq "">
<cfset arList[1][1] = qrySelectedID.ID_value>
<cfset arList[1][2] = qrySelectedID.display_value>
<cfset arList[2][1] = 0>
<cfset arList[2][2] = '*SELECT ONE*'>
<cfelse>
<cfset arList[1][1] = 0>
<cfset arList[1][2] = '*SELECT ONE*'>
</cfif>
<cfloop from="1" to="#qryListWBind.recordcount#" index="i">
   <cfif isDefined("arguments.selectedid") and arguments.selectedid neq "">
<cfset x = i + 2>
<cfelse>
<cfset x = i + 1>
</cfif>
<cfoutput>
    <cfset arList[x][1] = qryListWBind.ID_value[i]>
<cfset arList[x][2] = qryListWBind.display_value[i]>
</cfoutput>
</cfloop>
<cfreturn arList>
</cffunction>
 
<!--- Second function sets up values for your second CFSelect statement; set access to remote; returntype in this case is array --->
<cffunction name="cfcsecondfuntionname" access="remote" returntype="array" hint="second select list - send selectedsubid if coming from edit page">
<!--- the ID_value is automatically passed after you specify what select statement to get the ID_value from. You must list these in the same order you list them in the CFSelect bind () --->
<cfargument name="ID_value" type="numeric" required="yes">
<!--- if call is coming from an edit page where a value was already pre-selected, it will be passed here --->
<cfargument name="selectedsubid" default="" required="no">
<!--- Define variables and clears them ---> 
<cfset var qrySelectedSubID=""> 
<cfset var qryListWSubBind=""> 
<cfset var arSublist="">
<!--- if call from edit page, query to single out pre-selected values --->
<cfif isDefined("arguments.selectedsubid") and arguments.selectedsubid neq "">
<cfquery name="qrySelectedSubID" datasource="#datasource#">
SELECT Sub_ID_value, Sub_display_value
FROM table_with_second_values
WHERE Sub_ID_value = #arguments.selectedsubid#
</cfquery>
</cfif>
<!--- Define values for your array to place in second select--->
<!--- if call from edit page, eliminate pre-selected values from the rest of the values with cfif statement in where clause --->
<cfquery name="qryListWSubBind" datasource="#datasource#">
SELECT lsi.Sub_ID_value, lsi.Sub_display_value, lsi.FKfromFirstTable
FROM table_with_first_values li INNER JOIN
table_with_second_values lsi ON li.ID_value = lsi.FKfromFirstTable
WHERE lsi.FKfromFirstTable = <cfqueryparam value="#arguments.ID_value#" cfsqltype="cf_sql_integer"><cfif isDefined("arguments.selectedsubid") and arguments.selectedsubid neq ""> AND lsi.Sub_ID_value != #arguments.selectedsubid#</cfif>
ORDER BY lsi.FKfromFirstTable, lsi.Sub_display_value
</cfquery> 
<!--- Build array for first select. If editing, lists the preselected values first unless you choose something else in the first select list. --->
<cfset arSublist = arraynew(2)>
<cfif isDefined("arguments.selectedsubid") and (arguments.selectedsubid neq "")>
<cfif qrySelectedSubID.recordcount>
    <cfset arSublist[1][1] = qrySelectedSubID.Sub_ID_value>
<cfset arSublist[1][2] = qrySelectedSubID.Sub_display_value>
<cfset arSublist[2][1] = 0>
<cfset arSublist[2][2] = '*SELECT NEXT*'>
<cfelse>
    <cfset arSublist[1][1] = 0>
<cfset arSublist[1][2] = '*SELECT NEXT*'>
</cfif>
<cfelse>
<cfset arSublist[1][1] = 0>
<cfset arSublist[1][2] = '*SELECT NEXT*'>
</cfif>
<cfloop from="1" to="#qryListWSubBind.recordcount#" index="i">
<cfif isDefined("arguments.selectedsubid") and arguments.selectedsubid neq "">
    <cfif qrySelectedSubID.recordcount>
<cfset x = i + 2>
<cfelse>
<cfset x = i + 1>
</cfif>
<cfelse>
<cfset x = i + 1>
</cfif>
<cfset arSublist[x][1] = qryListWSubBind.Sub_ID_value[i]>
<cfset arSublist[x][2] = qryListWSubBind.Sub_display_value[i]>
</cfloop>
<cfreturn arSublist>
</cffunction>
</cfcomponent>
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:

Select allOpen in new window

 

by: panosmsPosted on 2009-01-13 at 07:16:06ID: 23363493

Hi DADITWebGroup.
Because i'm little confused now,how looks the select.cfm page with the two select boxes?Can you replace the names of the values a.s.o ?
i noticed you use cfselect.Can you change this with select?
Something else:
Looking around i found on this page:http://tutorial95.easycfm.com/ a tutorial that works with the two select boxes.
The difference between the code in the question and the code in the new example is that not all the values in the child list need to be loaded when the page loads.
Using the script:
<script language="JavaScript1.2">
        function whichLocal(obj){
                    switch (obj.selectBorder.selectedIndex){
                    <!--- use the group attribute to group output by category --->
                    <cfoutput query="getLocal" group="country">
                    <cfset mycase = mycase + 1>case #mycase#:
                    <cfset myList = ValueList(getLocal.country_id)>
                    <cfset numberInCountry = ListValueCount(myList, country_id)>
                         obj.selectLocal.length=#numberInCountry#<cfoutput><cfset idx = idx + 1>
                         obj.selectLocal.options[#idx#].value="#getLocal.location_id#"
                         obj.selectLocal.options[#idx#].text="#getLocal.State#"</cfoutput>
                         break;

                    <cfset idx = -1>
                    </cfoutput>
                    }
       }
    </script>
and changing the code to:
<script language="JavaScript1.2">
 <cfoutput query="getLocal" group="country">
                    <cfset mycase = mycase + 1>case #mycase#:
     <cfoutput>
         <cfset idx = idx + 1>
             obj.options[#idx#].value=new Option('#getLocal.State#','#getLocal.location_id#');
     </cfoutput>
 <cfset idx = -1>
                    </cfoutput>
                    }
       }
    </script>
I have a code that looks like the children.cfm:
<script language="JavaScript1.2">
       
            case 1:
         obj.options[0] = new Option('Child 1','1');
          obj.options[1] = new Option('Child 2','2');
          obj.options[2] = new Option('Child 3','3');
          obj.options[3] = new Option('Child 4','4');

case 2:
         obj.options[0] = new Option('Child 5','11');
          obj.options[1] = new Option('Child 6','12');
          obj.options[2] = new Option('Child 7','13');
          obj.options[3] = new Option('Child 8','14');
      }
   }
   </script>

but i cannot use there the cfcase tag to get the id from the parentquery and the <cfswitch expression="#parentCode#">.
I don't know if all these does anything mean to you.I only wanted to get the children.cfm with a query or script (or both of them)

 

by: DADITWebGroupPosted on 2009-01-13 at 07:44:27ID: 23363836

Here is an example using real code.  You need to use CFFORM and CFSELECT to generate the select statements in Coldfusion 8 as I do in my example.  I use this code a lot and it works everytime.  I have not tried doing it any other way as this works the way I want it to.

<!--- This is the page containing the CFSELECTs (either an edit or an add page which means one containing pre-recorded values and one that is not) --->
<cfform>
 <table>
  <tr>
    <!--- ADD Page --->
    <td><cfselect name="Place" bind="cfc:calendar.fnListWBind()" bindonload="true" value="rcid" display="title" /></td>
    <!--- EDIT Page --->
    <td><cfselect name="Place" bind="cfc:calendar.fnListWBind(#qryEvents.Place#)" bindonload="true" value="rcid" display="title" /></td>
  </tr>
  <tr>
    <!--- ADD Page --->
    <td><cfselect name="Contact" bind="cfc:calendar.fnListWSubBind({Place})" value="rcid" display="title" /></td>
    <!--- EDIT Page --->
    <td><cfselect name="Contact" bind="cfc:calendar.fnListWSubBind({Place},#qryEvents.Contact#)" value="rcid" display="title" /></td>
  </tr>
 </table>
</cfform>
<!--- Here is the Calendar.cfc that is located in the same folder (it doesnt have to be, but you will have to edit your path in dot notation... --->
 
<cfcomponent output="no">
  <cffunction name="fnListWBind" access="remote" returntype="array" hint="list to bind to subs">
    <cfargument name="selectedid" default="" required="no">
    <!--- Define variables --->  
    <cfset var qrySelectedID="">    
    <cfset var qryListWBind="">     
    <cfset var placeList="">
    <cfif isDefined("arguments.selectedid") and arguments.selectedid neq "">
      <cfquery name="qrySelectedID" datasource="DATA">
        SELECT RcId, Title
        FROM Calendar_ListsItems
        WHERE rcid = #arguments.selectedid#
      </cfquery>
    </cfif>
    <cfquery name="qryListWBind" datasource="DATA">
       SELECT     RcId, Title
       FROM      Calendar_ListsItems
       WHERE     0=0<cfif isDefined("arguments.selectedid") and arguments.selectedid neq ""> AND rcid != #arguments.selectedid#</cfif>
       ORDER BY 	Title
    </cfquery>
        
    <cfset placeList = arraynew(2)>
    <cfif isDefined("arguments.selectedid") and arguments.selectedid neq "">
      <cfset placeList[1][1] = qrySelectedID.rcid>
      <cfset placeList[1][2] = qrySelectedID.title>
      <cfset Placelist[2][1] = 0>
      <cfset Placelist[2][2] = '*SELECT A PLACE*'>
    <cfelse>
      <cfset placeList[1][1] = 0>
      <cfset placeList[1][2] = '*SELECT A PLACE*'>
    </cfif>
    <cfloop from="1" to="#qryListWBind.recordcount#" index="i">
	<cfif isDefined("arguments.selectedid") and arguments.selectedid neq "">
            <cfset x = i + 2>
         <cfelse>
            <cfset x = i + 1>
         </cfif>
        <cfoutput>
	  <cfset placeList[x][1] = qryListWBind.RcId[i]>
           <cfset placeList[x][2] = qryListWBind.Title[i]>
        </cfoutput>
      </cfloop>
    <cfreturn placeList>
  </cffunction>
 
  <cffunction name="fnListWSubBind" access="remote" returntype="array" hint="list of bound subs">
    <cfargument name="rcid" type="numeric" required="yes">
    <cfargument name="selectedsubid" default="" required="no">
    <!--- Define variables --->    
    <cfset var qrySelectedSubID="">  
    <cfset var qryListWSubBind="">           
    <cfset var placeSubList="">
    <cfif isDefined("arguments.selectedsubid") and arguments.selectedsubid neq "">
      <cfquery name="qrySelectedSubID" datasource="DATA">
         SELECT RcId, Title
         FROM Calendar_ListsSubItems
         WHERE listsitemsid = <cfqueryparam value="#arguments.rcid#" cfsqltype="cf_sql_integer"> AND rcid = #arguments.selectedsubid#
      </cfquery>
    </cfif>
    <cfquery name="qryListWSubBind" datasource="DATA">
      SELECT    lsi.rcid, lsi.Title, lsi.listsitemsid
      FROM      Calendar_ListsItems li INNER JOIN
                Calendar_ListsSubItems lsi ON li.rcid = lsi.listsitemsid
      WHERE     lsi.listsitemsid = <cfqueryparam value="#arguments.rcid#" cfsqltype="cf_sql_integer"><cfif isDefined("arguments.selectedsubid") and arguments.selectedsubid neq ""> AND lsi.rcid != #arguments.selectedsubid#</cfif>
      ORDER BY 	lsi.listsitemsid, lsi.Title
   </cfquery>
        
   <cfset placeSubList = arraynew(2)>
   <cfif isDefined("arguments.selectedsubid") and (arguments.selectedsubid neq "")>
     <cfif qrySelectedSubID.recordcount>
        <cfset placeSubList[1][1] = qrySelectedSubID.rcid>
        <cfset placeSubList[1][2] = qrySelectedSubID.title>
        <cfset placeSubList[2][1] = 0>
        <cfset placeSubList[2][2] = '*SELECT A Contact*'>
     <cfelse>
	<cfset placeSubList[1][1] = 0>
         <cfset placeSubList[1][2] = '*SELECT A Contact*'>
     </cfif>
   <cfelse>
     <cfset placeSubList[1][1] = 0>
     <cfset placeSubList[1][2] = '*SELECT A Contact*'>
   </cfif>
   <cfloop from="1" to="#qryListWSubBind.recordcount#" index="i">
      <cfif isDefined("arguments.selectedsubid") and arguments.selectedsubid neq "">
	<cfif qrySelectedSubID.recordcount>
            <cfset x = i + 2>
         <cfelse>
            <cfset x = i + 1>
         </cfif>
      <cfelse>
         <cfset x = i + 1>
      </cfif>
      <cfset placeSubList[x][1] = qryListWSubBind.rcid[i]>
      <cfset placeSubList[x][2] = qryListWSubBind.Title[i]>
    </cfloop>
    <cfreturn placeSubList>
  </cffunction>
</cfcomponent>
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:

Select allOpen in new window

 

by: panosmsPosted on 2009-01-14 at 00:08:35ID: 31531769

Hi  DADITWebGroup:.
I will accept your answer as the solution because it is good tutorial.Unfortunately i cannot use this because i have built the forms using an extension without the cfform-tags.
Thank you for your help.
Panos.
(As a Coldfusion expert can you help me with this question?:
http://www.experts-exchange.com/Software/Server_Software/Web_Servers/ColdFusion/Q_24043451.html

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...