AlanDI1
Programmer
- Apr 20, 2003
- 56
I have javascript code that I use with Coldfusion to load a second drop down that is related to a selection made in a first drop down. The code works but (isn't there always a but?), it depends on the quantity of items returned by the query.
The results of the query are about 40K entries. When I trim that down for testing purposes to about half that the code works without any errors. When I use all the data, I get a syntax error someplace in the generated arrays (exact location varies depending on the size of the result set).
Not sure if the problem is the number of arrays, the size of the arrays, total number of elements or something else.
<----- Code ------>
<!--- Select the Types and IDs. --->
<cfquery datasource="pb_view" name="GetIds">
SELECT DISTINCT Fac_Type, Fac_Ident
FROM dbo.ListTable_facility, dbo.naprs_reportable_facilities
WHERE Facility = Fac_type
ORDER BY Fac_Type, Fac_ident
</cfquery>
<script language = "JavaScript">
<!--
// For each type, create an array to hold the idents.
<cfoutput query="GetIds" group="Fac_Type">
// Create the array
TypeArray#Fac_Type# = new Array();
<cfset i = 0>
// Populate the array
<cfoutput>
<cfset i = i + 1>
TypeArray#Fac_Type#[#i#] = "#Fac_Ident#";
</cfoutput>
</cfoutput>
// Function to populate the Ident for the Type selected
function PopulateIdent() {
// Only process the function if the first item is not selected.
if (document.selectedForm.Fac_Type.selectedIndex != 0) {
// Find the state abbreviation
var ThisType = document.selectedForm.Fac_Type[document.selectedForm.Fac_Type.selectedIndex].value;
// Set the length of the ident drop down equal to the length of the type's array
document.selectedForm.Fac_Ident.length = eval("TypeArray" + ThisType + ".length");
// Put 'Select' as the first option in the ident drop-down
document.selectedForm.Fac_Ident[0].value = "";
document.selectedForm.Fac_Ident[0].text = "Select";
document.selectedForm.Fac_Ident[0].selected = true;
// Loop through the state's array and populate the area code drop down.
for (i=1; i<eval("TypeArray" + ThisType + ".length"); i++) {
document.selectedForm.Fac_Ident.value = eval("TypeArray" + ThisType + "");
document.selectedForm.Fac_Ident.text = eval("TypeArray" + ThisType + "");
}
}
}
//-->
</script>
<form name="selectedForm">
<p>
<table border="0">
<tr>
<td><b>Type</b></td>
<td><b>Ident</b></td>
</tr>
<tr>
<td>
<select name="Fac_Type" onChange="javascriptopulateIdent();">
<option value="0">Select Type</option>
<cfoutput query="GetIds" group="Fac_Type">
<option value="#Fac_Type#">#Fac_Type#</option>
</cfoutput>
</select>
</td>
<td>
<select name="Fac_Ident" width="70" style="width:180" >
<option value="0">Select Facility</option>
</select>
</td>
</tr>
</table>
</p>
</form>
Does anyone have any ideas and if so how do you increase whatever that it is to make this work.
The results of the query are about 40K entries. When I trim that down for testing purposes to about half that the code works without any errors. When I use all the data, I get a syntax error someplace in the generated arrays (exact location varies depending on the size of the result set).
Not sure if the problem is the number of arrays, the size of the arrays, total number of elements or something else.
<----- Code ------>
<!--- Select the Types and IDs. --->
<cfquery datasource="pb_view" name="GetIds">
SELECT DISTINCT Fac_Type, Fac_Ident
FROM dbo.ListTable_facility, dbo.naprs_reportable_facilities
WHERE Facility = Fac_type
ORDER BY Fac_Type, Fac_ident
</cfquery>
<script language = "JavaScript">
<!--
// For each type, create an array to hold the idents.
<cfoutput query="GetIds" group="Fac_Type">
// Create the array
TypeArray#Fac_Type# = new Array();
<cfset i = 0>
// Populate the array
<cfoutput>
<cfset i = i + 1>
TypeArray#Fac_Type#[#i#] = "#Fac_Ident#";
</cfoutput>
</cfoutput>
// Function to populate the Ident for the Type selected
function PopulateIdent() {
// Only process the function if the first item is not selected.
if (document.selectedForm.Fac_Type.selectedIndex != 0) {
// Find the state abbreviation
var ThisType = document.selectedForm.Fac_Type[document.selectedForm.Fac_Type.selectedIndex].value;
// Set the length of the ident drop down equal to the length of the type's array
document.selectedForm.Fac_Ident.length = eval("TypeArray" + ThisType + ".length");
// Put 'Select' as the first option in the ident drop-down
document.selectedForm.Fac_Ident[0].value = "";
document.selectedForm.Fac_Ident[0].text = "Select";
document.selectedForm.Fac_Ident[0].selected = true;
// Loop through the state's array and populate the area code drop down.
for (i=1; i<eval("TypeArray" + ThisType + ".length"); i++) {
document.selectedForm.Fac_Ident.value = eval("TypeArray" + ThisType + "");
document.selectedForm.Fac_Ident.text = eval("TypeArray" + ThisType + "");
}
}
}
//-->
</script>
<form name="selectedForm">
<p>
<table border="0">
<tr>
<td><b>Type</b></td>
<td><b>Ident</b></td>
</tr>
<tr>
<td>
<select name="Fac_Type" onChange="javascriptopulateIdent();">
<option value="0">Select Type</option>
<cfoutput query="GetIds" group="Fac_Type">
<option value="#Fac_Type#">#Fac_Type#</option>
</cfoutput>
</select>
</td>
<td>
<select name="Fac_Ident" width="70" style="width:180" >
<option value="0">Select Facility</option>
</select>
</td>
</tr>
</table>
</p>
</form>
Does anyone have any ideas and if so how do you increase whatever that it is to make this work.