I am not sure if this is the forum to add my problem, but my problem is Javascript. I am trying to use Javascript with ColdFusion MX 7 and Access.

Can someone help me by telling me what is wrong with this code. Initially I thought it was cool, but then when I tried to use it, it does not select any of the other lists. I got this code from another site, but it does not select the other lists:

I am using Dreamweaver 8, CFMX7, IE6, Access 2002


Thanks in advance.

--------------


I have one query (not sure if I should have one query for each select)

<cfquery name="qryLocationInfo" datasource="mydsn">
SELECT DISTINCT city, state, address
FROM Location_Table
ORDER BY state, city, address
</cfquery>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Multiple three selects related</title>

<script TYPE="text/javascript">
<!--
//create the initial array to hold the different records.

var aryLocation = new Array();

//Now to bring in the data. This is a combination of ColdFusion and JavaScript

<!--- We set a variable for our loop to insert the data. The loop starts at zero because JavaScript arrays start at zero. --->

<cfset Variables.JSLoop = 0>


//The next lines create an array of 3 items in the outer array. It could hold more than three items if we needed more than 3 selects related.

<cfoutput>
<cfloop query="qryLocationInfo">
aryLocation[#Variables.JSLoop#] = new Array("#trim(qryLocationInfo.state)#", "#trim(qryLocationInfo.city)#", "#trim(qryLocationInfo.address)#");
<cfset Variables.JSLoop = Variables.JSLoop + 1>
</cfloop>
</cfoutput>

<!--- Should I change these name to my select names (city, state, address or to the looped names mycity, mystate, myaddress?--->

function tsrUpdSelect(frstSelect, scndSelect, thrdSelect, thisSelect)

{
//This function takes four arguments.

/*
They will be the frstSel (the state select box), the scndSel (the city select box),
the thrdSel (the address select box) and thisSel (the select box that
actually called for the change to occur).
*/

//local variables
var i; var chkCty = "";
<!---Do I change the scndSelect word to my actual second select name?--->
//see if we just changed the first select box (state).
if(thisSelect.name == frstSelect.name) {
//set the length of the other selects to zero to empty them
scndSelect.options.length = 0;
thrdSelect.options.length = 0;

//set the first option for each (being messages to do a select).
scndSelect.options[scndSelect.length] = new Option("Choose City", "");
thrdSelect.options[thrdSelect.length] = new Option("Choose Address", "");

//Now loop through and set the second option list (city).
//If a state was chosen. There is also code to prevent duplicate
//cities. This could happen if a city had multiple addresses.
if(thisSelect.options[thisSelect.selectedIndex].value != "")
{
for (i = 0; i <aryLocation.length; i++)

{
if(aryLocation[0] == thisSelect.options[thisSelect.selectedIndex].value && chkCty.lastIndexOf(aryLocation[1] == -1))
{scndSelect.options[scndSelect.length] = new Option(aryLocation[1], aryLocation[1]); chkCty = chkCty + "," + aryLocation[1];
}
}
}
}
}
//see if we just changed the second select box(city).
if(thisSelect.name == scndSelect.name)
{
//set the length of the third select to zero.
thrdSelect.options.length = 0;
//set the first option.
thrdSelect.options[thrdSelect.length] = new Option("Choose Address", "");
//set the rest of the values if a city was chosen.
for(i=0; i <aryLocation.length; i++)
{
if(aryLocation[0] == frstSelect.options[frstSelect.selectedIndex].value && aryLocation[1] == scndSelect.options[scndSelect.selectedIndex].value) {thrdSelect.options[thrdSelect.length] = new Option(aryLocation[2], aryLocation[2])
}
}

}
//-->
</script>
</head>
<body>
<!---Should there be a SelectedIndex in this form someplace?--->
<!---When where do I use "selected" in the Options area, if I am supposed to?--->

<cfoutput>
<form method="post" name="testForm">
<table>
<tr>
<th>State</th>
<th>City</th>
<th>Address</th>
</tr>
<cfloop from="1" to="5" index="Variables.myLoop">
<tr>
<td>
<cfset stateList = "">
<select name="mystate#myLoop#" onChange="tsrUpdSelect(this, testForm.scndSelect#myLoop#, testForm.thrdSelect#myLoop#, this);">
<option value="" selected>Choose State</option>
<cfloop query="qryLocationInfo">
<cfif NOT ListFindNoCase(stateList, qryLocationInfo.state, ",")>
<option value="#trim(qryLocationInfo.state)#">#trim(qryLocationInfo.state)#</option>
<cfset stateList = ListAppend(stateList, qryLocationInfo.state, ",")>
</cfif>
</cfloop>
</select>
</td>

<td>
<select name="mycity#myLoop#" onChange="tsrUpdSelect(testForm.frstSelect#myLoop#, this, testForm.thrdSelect#myLoop#, this);">
<option value="" selected>Choose City</option>
</select>
</td>

<td>
<select name="myaddr#myLoop#">
<option value="" selected>Choose Address</option>
</select>
</td>

</tr>
</cfloop>
</table>
</form>
</cfoutput>
</body>
</html>

Thanks for all help. I am JS challenged!