I am new to programming ColdFusion and I am right now having a problem
with my code for dynamic drop down lists. what I want to do is have a
student select a state and have another field populate with
corresponding schools. after doing some searching I found this site:
http://www.webtricks.com/sourcecode/source_code.cfm?CodeID=18
<http://www.webtricks.com/sourcecode/source_code.cfm?CodeID=18>. I
modified the code as follows:
<!-- Retreave all States with High school information-->
<cfquery name="GetState" datasource="datasource">
Select S.State, HS.HSState
From States S, HighSchoolInfo HS
Where S.State=HS.HSState
order by State desc
</cfquery>
<!-- Retreave the High schools -->
<cfquery name="GetHighSchool" datasource="datasource">
SELECT HighSchoolInfo.HSCode, HighSchoolInfo.HSName,
HighSchoolInfo.HSCity, HighSchoolInfo.HSState
FROM HighSchoolInfo
ORDER BY HSName
</cfquery>
<script language = "JavaScript">
<!--
// For each state, create an array to hold the area codes.
// Each state array will be identified by the two-character state
abbreviation
<cfoutput query="GetState" group="State">
// Create the array
StateArray#State# = new Array();
<cfset i = 0>
// Populate the array
<cfoutput>
<cfset i = i + 1>
StateArray#State#[#i#] = #HSState#;
</cfoutput>
</cfoutput>
// Function to populate the Highschool for the state selected
function PopulateHSName() {
// Only process the function if the first item is not selected.
if (document.StateForm.State.selectedIndex != 0) {
// Find the state abbreviation
var ThisState =
document.StateForm.State[document.StateForm.State.selectedIndex].value;
// Set the length of the arecode drop down equal to the length of the
state's array
document.StateForm.HSName.length = eval("StateArray" + ThisState +
".length");
// Put 'Select' as the first option in the Highschool drop-down
document.StateForm.HSName[0].value = "";
document.StateForm.HSName[0].text = "Select";
document.StateForm.HSName[0].selected = true;
// Loop through the state's array and populate the Highschool drop down.
for (i=1; i<eval("StateArray" + ThisState + ".length"); i++) {
document.StateForm.HSName[i].value = eval("StateArray" + ThisState +
"[i]");
document.StateForm.HSName[i].text = eval("StateArray" + ThisState + "[i]");
}
}
}
//-->
</script>
<select name="State" tabindex="12" onChange="PopulateHSName()">
<option value="0">Select State
<cfoutput query="GetState" group="State">
<option>#State#
</cfoutput>
</select>
<select name="HSName" tabindex="19">
<option value="0">Select High School
<cfoutput query="getHighSchool">
<option value="#HSCode#">#UCase(HSName)# -- #UCase(HSCity)#,
#UCase(HSState)#
</cfoutput>
</select>
Please help I have no clue where I screwed up, it shows the states in
the right order, but it still shows all the high schools in the database.
Thanks a bunch
-Rob
--
Robert Nunez II
IS Technical Services Assistant
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create robust enterprise, web RIAs.
Upgrade & integrate Adobe Coldfusion MX7 with Flex 2
http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJP
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:279494
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4