I want to use checkboxes so when checked the dropdown menu would get populated dyamically in turn populate another drop down. I can't seem to get this to work. Please help.
Thanks
<!--- Select the states and area codes. --->
<CFQUERY DATASOURCE = "States" NAME = "GetStates">
SELECT S.State, S.StateCode, AC.AreaCode, AC.Note
FROM States S, AreaCodes AC
WHERE S.StateCode = AC.StateCode
ORDER BY S.State, AC.AreaCode, AC.Note
</CFQUERY>
<!--- Select all the area codes. --->
<CFQUERY DATASOURCE = "States" NAME = "GetCodes">
SELECT AreaCode, Note
FROM AreaCodes
ORDER BY AreaCode
</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 = "GetStates" GROUP = "State">
// Create the array
StateArray#StateCode# = new Array();
<CFSET i = 0>
// Populate the array
<CFOUTPUT>
<CFSET i = i + 1>
StateArray#StateCode#[#i#] = #AreaCode#;
</CFOUTPUT>
</CFOUTPUT>
// Function to populate the area codes for the state selected
function PopulateAreaCode()
{
// Only process the function if the first item is not selected.
if (document.StateForm.StateCode.selectedIndex != 0)
{
// Find the state abbreviation
var ThisState = document.StateForm.StateCode[document.StateForm.StateCode.selectedIndex].value;
// Set the length of the arecode drop down equal to the length of the state's array
document.StateForm.AreaCode.length = eval("StateArray" + ThisState + ".length"
;
// Put 'Select' as the first option in the area code drop-down
document.StateForm.AreaCode[0].value = "";
document.StateForm.AreaCode[0].text = "Area Code";
document.StateForm.AreaCode[0].selected = true;
// Loop through the state's array and populate the area code drop down.
for (i=1; i<eval("StateArray" + ThisState + ".length"
; i++)
{
document.StateForm.AreaCode.value = eval("StateArray" + ThisState + ""
;
document.StateForm.AreaCode.text = eval("StateArray" + ThisState + ""
;
}
}
}
function PopulateArea()
{
// Only process the function if the first item is not selected.
if (document.StateForm.StateCode.selectedIndex != 0)
{
// Find the state abbreviation
var ThisState = document.StateForm.StateCode[document.StateForm.StateCode.selectedIndex].value;
// Set the length of the arecode drop down equal to the length of the state's array
document.StateForm.Area.length = eval("StateArray" + ThisState + ".length"
;
// Put 'Select' as the first option in the area code drop-down
document.StateForm.Area[0].value = "";
document.StateForm.Area[0].text = "State Description";
document.StateForm.Area[0].selected = true;
// Loop through the state's array and populate the area code drop down.
for (i=1; i<eval("StateArray" + ThisState + ".length"
; i++)
{
document.StateForm.Area.value = eval("StateArray" + ThisState + ""
;
document.StateForm.Area.text = eval("StateArray" + ThisState + ""
;
}
}
}
//-->
</SCRIPT>
<FORM NAME = "StateForm">
<TABLE BORDER = "0">
<TR>
<TD><B>State</B></TD>
<TD><B>Area Code</B></TD>
<TD><B>State Description</B></TD>
</TR>
<TR>
<TD>
<cfoutput query="GetStates" group="State" maxrows=5>
<input type="checkbox" onClick="PopulateAreaCode()">
#State#
</CFOUTPUT>
</SELECT>
</TD>
<TD>
<select name="AreaCode" size="5" wide="150" onChange="PopulateArea()">
<OPTION VALUE = "0">Select Area Code
<CFOUTPUT QUERY = "GetCodes">
<OPTION VALUE = "#AreaCode#">#AreaCode#
</CFOUTPUT>
</SELECT>
</TD>
<TD>
<select name="Area" size="5" wide="150">
<OPTION VALUE = "0">Select State Description
<CFOUTPUT QUERY = "Getstates">
<OPTION VALUE = "#Note#">#Note#
</CFOUTPUT>
</SELECT>
</TD>
</TR>
</TABLE>
</FORM
Thanks
<!--- Select the states and area codes. --->
<CFQUERY DATASOURCE = "States" NAME = "GetStates">
SELECT S.State, S.StateCode, AC.AreaCode, AC.Note
FROM States S, AreaCodes AC
WHERE S.StateCode = AC.StateCode
ORDER BY S.State, AC.AreaCode, AC.Note
</CFQUERY>
<!--- Select all the area codes. --->
<CFQUERY DATASOURCE = "States" NAME = "GetCodes">
SELECT AreaCode, Note
FROM AreaCodes
ORDER BY AreaCode
</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 = "GetStates" GROUP = "State">
// Create the array
StateArray#StateCode# = new Array();
<CFSET i = 0>
// Populate the array
<CFOUTPUT>
<CFSET i = i + 1>
StateArray#StateCode#[#i#] = #AreaCode#;
</CFOUTPUT>
</CFOUTPUT>
// Function to populate the area codes for the state selected
function PopulateAreaCode()
{
// Only process the function if the first item is not selected.
if (document.StateForm.StateCode.selectedIndex != 0)
{
// Find the state abbreviation
var ThisState = document.StateForm.StateCode[document.StateForm.StateCode.selectedIndex].value;
// Set the length of the arecode drop down equal to the length of the state's array
document.StateForm.AreaCode.length = eval("StateArray" + ThisState + ".length"
// Put 'Select' as the first option in the area code drop-down
document.StateForm.AreaCode[0].value = "";
document.StateForm.AreaCode[0].text = "Area Code";
document.StateForm.AreaCode[0].selected = true;
// Loop through the state's array and populate the area code drop down.
for (i=1; i<eval("StateArray" + ThisState + ".length"
{
document.StateForm.AreaCode.value = eval("StateArray" + ThisState + ""
document.StateForm.AreaCode.text = eval("StateArray" + ThisState + ""
}
}
}
function PopulateArea()
{
// Only process the function if the first item is not selected.
if (document.StateForm.StateCode.selectedIndex != 0)
{
// Find the state abbreviation
var ThisState = document.StateForm.StateCode[document.StateForm.StateCode.selectedIndex].value;
// Set the length of the arecode drop down equal to the length of the state's array
document.StateForm.Area.length = eval("StateArray" + ThisState + ".length"
// Put 'Select' as the first option in the area code drop-down
document.StateForm.Area[0].value = "";
document.StateForm.Area[0].text = "State Description";
document.StateForm.Area[0].selected = true;
// Loop through the state's array and populate the area code drop down.
for (i=1; i<eval("StateArray" + ThisState + ".length"
{
document.StateForm.Area.value = eval("StateArray" + ThisState + ""
document.StateForm.Area.text = eval("StateArray" + ThisState + ""
}
}
}
//-->
</SCRIPT>
<FORM NAME = "StateForm">
<TABLE BORDER = "0">
<TR>
<TD><B>State</B></TD>
<TD><B>Area Code</B></TD>
<TD><B>State Description</B></TD>
</TR>
<TR>
<TD>
<cfoutput query="GetStates" group="State" maxrows=5>
<input type="checkbox" onClick="PopulateAreaCode()">
#State#
</CFOUTPUT>
</SELECT>
</TD>
<TD>
<select name="AreaCode" size="5" wide="150" onChange="PopulateArea()">
<OPTION VALUE = "0">Select Area Code
<CFOUTPUT QUERY = "GetCodes">
<OPTION VALUE = "#AreaCode#">#AreaCode#
</CFOUTPUT>
</SELECT>
</TD>
<TD>
<select name="Area" size="5" wide="150">
<OPTION VALUE = "0">Select State Description
<CFOUTPUT QUERY = "Getstates">
<OPTION VALUE = "#Note#">#Note#
</CFOUTPUT>
</SELECT>
</TD>
</TR>
</TABLE>
</FORM