ok I've tried to work through this myself for several days, but there's something I'm missing. Either my queries are wrong, or my functions are wrong.
I'm using Ben Fortas CF AJAX dynamic select drop downs tutorial and everything is working with no errors, but I'm not getting the desired functionality.
I have a cars database with two tables: one for makes which includes two columns manufactureID and manufactureBrand
The second table is models: which includes modelID, model, manufactureID(FK), and modelYear.
Here is my cfc:
<cfcomponent output="false">
<!--- Set datasource --->
<cfset THIS.dsn="rlbulbs">
<!--- Function to get data from datasource --->
<!--- Get array of car manufactures --->
<cffunction name="getMakes" access="remote" returntype="array">
<!--- Set variables --->
<cfset var data="">
<cfset var result=ArrayNew(2)>
<cfset var i=0>
<!--- Query DB --->
<cfquery name="data" datasource="#THIS.dsn#">
SELECT manufactureID, manufactureBrand
FROM manufacture
ORDER BY manufactureBrand
</cfquery>
<!--- loop through makes and convert to array--->
<cfloop index="i" from="1" to="#data.RecordCount#">
<cfset result[i][1]=data.manufactureID[i]>
<cfset result[i][2]=data.manufactureBrand[i]>
</cfloop>
<!--- Return results --->
<cfreturn result>
</cffunction>
<!--- Get Models by Make --->
<cffunction name="getModels" access="remote" returnType="array">
<cfargument name="manufactureID" type="numeric" required="true">
<!--- Get data --->
<cfquery name="data" datasource="#THIS.dsn#">
SELECT modelID, models
FROM models
WHERE manufactureID = #ARGUMENTS.manufactureID#
ORDER BY models
</cfquery>
<!--- Convert to Array --->
<cfloop index="i" from="1" to="#data.RecordCount#">
<cfset result[i][1]=data.modelID[i]>
<cfset result[i][2]=data.models[i]>
</cfloop>
<!--- and return results --->
<cfreturn result>
</cffunction>
<!--- Get models by year --->
<cffunction name="getYears" access="remote" returnType="array">
<cfargument name="modelID" type="numeric" required="true">
<!--- Get Data --->
<cfquery name="data" datasource="#THIS.dsn#">
SELECT modelID, modelYear
FROM models
<!--- WHERE modelYear = #ARGUMENTS.modelID# --->
GROUP BY modelYear
</cfquery>
<!--- Convert to Array --->
<cfloop index="i" from="1" to="#data.RecordCount#">
<cfset result[i][1]=data.modelID[i]>
<cfset result[i][2]=data.modelYear[i]>
</cfloop>
<!--- and return results --->
<cfreturn result>
</cffunction>
</cfcomponent>
and my cfm:
<cfform>
<table>
<tr>
<td>Select Your Make:</td>
<td><cfselect name="manufactureID"
bind="cfc:cars.getMakes()"
bindonload="true" /></td>
</tr>
<tr>
<td>Select Your Year</td>
<td><cfselect name="modelYear"
id="modelYear"
bind="cfc:cars.getYears({modelID})" />
</td>
</tr>
<tr>
<td>Select Your Model</td>
<td><cfselect name="modelID"
bind="cfc:cars.getModels({manufactureID})" /></td>
</tr>
</table>
</cfform>
As I said, the select lists populate fine, and when I select another make, the models populate based on the make selected. My problem is when I try to select a Year, the models dont change based on that selection. Any help would be appreciated. Thanks!