I'm ready to tear my hair out! Can anybody find why the data in the third dropdown list is not correct? When I dump it, everything is correct. But in the dropdown, it's all wrong.
Code:
<cfquery name="getAuto" datasource="thisSource">
SELECT TFAutoMake.ID, TFAutoMake.Make, TFAutoModel.MakeID, TFAutoModel.Model, TFAutoModel.ModelID
FROM TFAutoMake, TFAutoModel
WHERE TFAutoMake.ID = TFAutoModel.MakeID
ORDER BY TFAutoMake.Make, TFAutoModel.Model
</cfquery>
<cfquery name="getModelYear" datasource="thisSource">
SELECT TFAutoModel.Model, TFAutoModel.ModelID, TFAutoModelYear.YearID, TFAutoModelYear.ModelYear
FROM TFAutoModel, TFAutoModelYear
WHERE TFAutoModel.ModelID = TFAutoModelYear.YearID
ORDER BY TFAutoModel.Model, TFAutoModelYear.ModelYear
</cfquery>
<cfset idx = -1>
<cfset myauto = 0>
<!--- send the selected make to determine the model list to display --->
<script language="JavaScript1.2">
function whichAuto(obj){
switch (obj.selectMake.selectedIndex){
<!--- use the group attribute to group output by category --->
<cfoutput query="getAuto" group="Make">
<cfset myauto = myauto + 1>case #myauto#:
<cfset autoList = ValueList(getAuto.ID)>
<cfset numberInMake = ListValueCount(autoList, MakeID)>
obj.selectModel.length=#numberInMake#<cfoutput><cfset idx = idx + 1>
obj.selectModel.options[#idx#].value="#getAuto.MakeID#"
obj.selectModel.options[#idx#].text="#getAuto.Model#"</cfoutput>
break;
<cfset idx = -1>
</cfoutput>
}
}
</script>
<cfset idx = -1>
<cfset myYear = -1>
<!--- send the selected make to determine the model list to display --->
<script language="JavaScript1.2">
function whichYear(obj){
switch (obj.selectModel.selectedIndex){
<!--- use the group attribute to group output by category --->
<cfoutput query="getModelYear" group="Model">
<cfset myYear = myYear + 1>case #myYear#:
<cfset yearList = ValueList(getModelYear.ModelID)>
<cfset numberInModel = ListValueCount(yearList, YearID)>
obj.selectYear.length=#numberInModel#<cfoutput><cfset idx = idx + 1>
obj.selectYear.options[#idx#].value="#getModelYear.ModelID#"
obj.selectYear.options[#idx#].text="#getModelYear.ModelYear#"</cfoutput>
break;
<cfset idx = -1>
</cfoutput>
}
}
</script>
<form name="myform">
<table>
<tr>
<td>
<select name="selectMake" onChange="whichAuto(this.form)">
<option>-Select Make-</option>
<!--- again, use the group attribute to group output by category --->
<cfoutput query="getAuto" group="Make">
<option value="#MakeID#">#Make#</option>
</cfoutput>
</select>
<select name="selectModel" onChange="whichYear(this.form)">
<cfif NOT isDefined("form.selectMake")>
<option>-Select Model-</option>
<cfelse>
<!--- again, use the group attribute to group output by category --->
<cfoutput query="getModelYear" group="Model">
<option value="#ModelID#">#Model#</option>
</cfoutput>
</cfif>
</select>
<select name="selectYear">
<cfif NOT isDefined("form.selectModel")>
<option>-Select Year-</option>
<cfelse>
<!--- again, use the group attribute to group output by category --->
<cfoutput query="getModelYear" group="Year">
<option value="#YearID#">#ModelYear#</option>
</cfoutput>
</cfif>
</select>
</td>
</tr>
</table>
</form>