Alright so people were not understanding clearly my question, so I removed the url where there was a question already asked by someone else and there I didn't got the perfect answer..
So here is the Question........
I am looking to code a dynamic drop down list within ColdFusion. What I want is the drop down list to be populated by the above drop down list (example: Select Province (B.C) will populate the City drop down list with all cities within that Province). Province data will be collected from a ColdFusion query and same with the city's data.
Please, No JavaScript, No AJAX, No ColdFusion CFCs, Nothing more than or less than some ColdFusion Tags... :( The logic code should be in one .cfm file itself.
@Charles Higgins
Can't seem to make it work. It's throwing "Error invoking CFC BinFcns.cfc : Internal Server Error" "Please tell me where I'm doing it wrong, here is the code..
This one is 'index.cfm'
<cfquery name="qstates" datasource="info">
SELECT states
FROM info
GROUP BY states
</cfquery>
<html>
<head>
</head>
<body>
<cfform>
<cfselect name="DropDown1" bind="cfc:BinFcns.Method({DropDown1})">
<cfoutput query="qstates"><option>#states#</option></cfoutput>
</cfselect>
<cfselect name="DropDown2" bind="cfc:BinFcns.Method({DropDown1})" />
</cfform>
</body>
</html>
and this one is the .cfc, 'BinFcns.cfc'
<cfcomponent output="true">
<!--- set function name --->
<cffunction name="Method" access="remote" returnType="array">
<!--- this is what you passed to the CFC via the {} think in the select --->
<cfargument name="Selected" type="numeric" required="true">
<!--- Define array to produce the drop down --->
<cfset var data="">
<cfset var result=ArrayNew(2)>
<cfset var i=0>
<!--- Get data --->
<cfquery name="data" datasource="info">
SELECT *
FROM info
Order by cities
</cfquery>
<!--- Convert results to array --->
<cfloop index="i" from="1" to="#data.RecordCount#">
<cfset result[i][1]=data.DropDownID[i]>
<cfset result[i][2]='#DropDownTEXT#'>
<!--- determine which is selected via what you passed and something in the database --->
<cfif data.DropDownID[i] eq #Selected#>
<cfset result[i][3]=true>
</cfif>
</cfloop>
<!--- And return it --->
<cfreturn result>
</cffunction>
</cfcomponent>
Your CFC Its not complicated, trust me learn its the best option, I have not tested this code but it should be close to working.. just fugly like most of my code.
<cfcomponent output="false">
<!--- set function name --->
<cffunction name="Method" access="public" returnType="array">
<!--- this is what you passed to the CFC via the {} think in the select --->
<cfargument name="Selected" type="numeric" required="true">
<!--- Define array to produce the drop down --->
<cfset var data="">
<cfset var result=ArrayNew(2)>
<cfset var i=0>
<!--- Get data --->
<cfquery name="data" datasource="#THIS.dsn#">
SELECT *
FROM 2ndDropDownData
Order by DataName
</cfquery>
<!--- Convert results to array --->
<cfloop index="i" from="1" to="#data.RecordCount#">
<cfset result[i][1]=data.DropDownID[i]>
<cfset result[i][2]='#DropDownTEXT#'>
<!--- determine which is selected via what you passed and something in the database --->
<cfif data.DropDownID[i] eq #Selected#>
<cfset result[i][3]=true>
</cfif>
</cfloop>
<!--- And return it --->
<cfreturn result>
</cffunction>
</cffunction>
The CFM SIMPLE!
A drop down called DropDown1, then you pass that to the cfc via the following code for drop down 2
<cfselect name="DropDown2" bind="cfc:cfcname.Method({DropDown1})" />
Its that simple... two drop downs, with the second one calling the CFC.. Worth learning.
You can use Bindonload, on the 2nd to preselect if required.
Anyway hope that stops you being scared of CFCs.. they are very usefull.