Below I have attached some code that is populating a select box. It is reeaing a CF query into a JS 1D array and outputting the array into a selsect box. My problem is that I want to make the JS array 2D and when I try to do this, nothing works. If anyone can help out I would appreciate it.
1D Array (Working)
=====================================================================
<cfoutput query="project_array" group="div">
<cfoutput group="sec">
// Create the array
projectArray#div##sec# = new Array(1);
<cfset x = 0>
// Populate the array
<cfoutput>
<cfset x = x + 1>
projectArray#div##sec#[#x#]= #id#;
</cfoutput>
</cfoutput>
</cfoutput>
// Function to populate the sections for the division selected
function PopulateProject()
{
// Only process the function if the first item is not selected.
if (document.qa_review.section.selectedIndex != -1)
{
// Find the division and section
var thisDiv = document.qa_review.division[document.qa_review.division.selectedIndex].value;
var thisSec = document.qa_review.section[document.qa_review.section.selectedIndex].value;
// Set the length of the section drop down equal to the length of the division array
document.qa_review.project.length = eval("projectArray" + thisDiv + thisSec + ".length"
// Put 'Select' as the first option in the section drop-down
document.qa_review.project[0].value = "";
document.qa_review.project[0].text = "-Select-";
document.qa_review.project[0].selected = true;
// Loop through the division array and populate the section drop down.
for (x=1; x<eval("projectArray" + thisDiv + thisSec + ".length" x++)
{
document.qa_review.project[x].value = eval("projectArray" + thisDiv + thisSec + "[x]"
document.qa_review.project[x].text = eval("projectArray" + thisDiv + thisSec + "[x]"
}
}
}
Attempt at 2D Array (Not Working)
Array works fine, but drop down will not populate.
=================================================================
<cfoutput query="project_array" group="div">
<cfoutput group="sec">
// Create the array
projectArray#div##sec# = new Array(2);
<cfset x = 0>
// Populate the array
<cfoutput>
<cfset x = x + 1>
projectArray#div##sec#[#x#][1]= #id#;
projectArray#div##sec#[#x#][2]= #name#;
</cfoutput>
</cfoutput>
</cfoutput>
// Function to populate the sections for the division selected
function PopulateProject()
{
// Only process the function if the first item is not selected.
if (document.qa_review.section.selectedIndex != -1)
{
// Find the division and section
var thisDiv = document.qa_review.division[document.qa_review.division.selectedIndex].value;
var thisSec = document.qa_review.section[document.qa_review.section.selectedIndex].value;
// Set the length of the section drop down equal to the length of the division array
document.qa_review.project.length = eval("projectArray" + thisDiv + thisSec + ".length"
// Put 'Select' as the first option in the section drop-down
document.qa_review.project[0].value = "";
document.qa_review.project[0].text = "-Select-";
document.qa_review.project[0].selected = true;
// Loop through the division array and populate the section drop down.
for (x=1; x<eval("projectArray" + thisDiv + thisSec + ".length" x++)
{
document.qa_review.project[x].value = eval("projectArray" + thisDiv + thisSec + "[x][1]"
document.qa_review.project[x].text = eval("projectArray" + thisDiv + thisSec + "[x][2]"
}
}
}
1D Array (Working)
=====================================================================
<cfoutput query="project_array" group="div">
<cfoutput group="sec">
// Create the array
projectArray#div##sec# = new Array(1);
<cfset x = 0>
// Populate the array
<cfoutput>
<cfset x = x + 1>
projectArray#div##sec#[#x#]= #id#;
</cfoutput>
</cfoutput>
</cfoutput>
// Function to populate the sections for the division selected
function PopulateProject()
{
// Only process the function if the first item is not selected.
if (document.qa_review.section.selectedIndex != -1)
{
// Find the division and section
var thisDiv = document.qa_review.division[document.qa_review.division.selectedIndex].value;
var thisSec = document.qa_review.section[document.qa_review.section.selectedIndex].value;
// Set the length of the section drop down equal to the length of the division array
document.qa_review.project.length = eval("projectArray" + thisDiv + thisSec + ".length"
// Put 'Select' as the first option in the section drop-down
document.qa_review.project[0].value = "";
document.qa_review.project[0].text = "-Select-";
document.qa_review.project[0].selected = true;
// Loop through the division array and populate the section drop down.
for (x=1; x<eval("projectArray" + thisDiv + thisSec + ".length" x++)
{
document.qa_review.project[x].value = eval("projectArray" + thisDiv + thisSec + "[x]"
document.qa_review.project[x].text = eval("projectArray" + thisDiv + thisSec + "[x]"
}
}
}
Attempt at 2D Array (Not Working)
Array works fine, but drop down will not populate.
=================================================================
<cfoutput query="project_array" group="div">
<cfoutput group="sec">
// Create the array
projectArray#div##sec# = new Array(2);
<cfset x = 0>
// Populate the array
<cfoutput>
<cfset x = x + 1>
projectArray#div##sec#[#x#][1]= #id#;
projectArray#div##sec#[#x#][2]= #name#;
</cfoutput>
</cfoutput>
</cfoutput>
// Function to populate the sections for the division selected
function PopulateProject()
{
// Only process the function if the first item is not selected.
if (document.qa_review.section.selectedIndex != -1)
{
// Find the division and section
var thisDiv = document.qa_review.division[document.qa_review.division.selectedIndex].value;
var thisSec = document.qa_review.section[document.qa_review.section.selectedIndex].value;
// Set the length of the section drop down equal to the length of the division array
document.qa_review.project.length = eval("projectArray" + thisDiv + thisSec + ".length"
// Put 'Select' as the first option in the section drop-down
document.qa_review.project[0].value = "";
document.qa_review.project[0].text = "-Select-";
document.qa_review.project[0].selected = true;
// Loop through the division array and populate the section drop down.
for (x=1; x<eval("projectArray" + thisDiv + thisSec + ".length" x++)
{
document.qa_review.project[x].value = eval("projectArray" + thisDiv + thisSec + "[x][1]"
document.qa_review.project[x].text = eval("projectArray" + thisDiv + thisSec + "[x][2]"
}
}
}