Using the SQL, Javascript and CF code below, how can I add the
functionality of adding a third hierarchical level to the form select
boxes but if a third level does not exist in the database table, it will
show as 'Not Populated' in a third form select box and the value will be
taken from the second select box for the form processing page.

 

DB Structure is as follows

 

CATNO   

CATEGORY

PARENT_LEVEL

0

Documents

 

1

Main Category 1

0

2

Main Category 2

0

1.1

Child Category 1

1

2.1

Child Category 2

2

1.11

3rd Level Category 1

1.1

2.11

3rd Level Category 2

2.1

 

Any ideas would be most helpful ?

 

Thanks

 

Ian

 

<!--- COLDFUSION CODE --->

 

<cfquery name="pull_cat" datasource="">

Select catno, category

>From docmenu

Where parent_level = 0

Order by category

</cfquery>

 

 

<cfquery name="pull_sub_cat" datasource="">

Select catno, category, parent_level

>From docmenu

Where parent_level is not null

Order by parent_level, category

</cfquery>

 

 <!--- JAVASCRIPT CODE --->

 

 

<script language="javascript">

 

//make sure you specify the group="...." here

 

<cfoutput query="pull_sub_cat" group="parent_level">

 

//create 2D array 

//[0] will hold the primary key of the sub category the other, [1], the
sub category name

 

var subArray_2Vals_#parent_level# = new Array();

 

<cfset arrayCount = 0>

 

<cfoutput>

subArray_2Vals_#parent_level#[#arrayCount#] = new Array ();

subArray_2Vals_#parent_level#[#arrayCount#][0] = "#catno#";

subArray_2Vals_#parent_level#[#arrayCount#][1] = "#Trim(category)#";

<cfset arrayCount = arrayCount + 1> 

</cfoutput>

 

</cfoutput>

 

//The function to call up the proper sub categories

function getSubs() {

 

//catVal is the current selected Category

catVal =
document.form.cat.options[document.form.cat.selectedIndex].value;

 

//empty any old values out of the sub category drop down

document.form.sub_cat.length = 0;

 

//I use 0 for my default "select a category first option".. you can use
whatever you'd like. Basically if

//no category is selected set the sub category drop down back to the
default of "select a 

// category first"

 

if(catVal == "none") {

document.form.sub_cat.options[0] = new Option('-- Select a Category
First --', 0);

}

else {

var full_2val_Name = "subArray_2Vals_" + parseInt(catVal);

var val_array = eval(full_2val_Name);

 

 

//loop through the proper sub category array making new options in 

//the sub category drop down as you go along

 

for(var i=0; i < val_array.length; i++) {

 

document.form.sub_cat.options[i] = new Option(val_array[i][1],
val_array[i][0]);

 

}

}

}

</script>

 

 

 <!--- FORM SELECT BOXES CODE --->

 

<select name="cat" onchange="getSubs();">

<option value="none">-- Select A Main Category --

<option></option>

<cfoutput query="pull_cat">

<option value="#catno#">#category#

</cfoutput>

</select>

 

<select  name="sub_cat">

<option value="none">-- Select a Main Category First --

</select>



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Upgrade to Adobe ColdFusion MX7 
Experience Flex 2 & MX7 integration & create powerful cross-platform RIAs 
http:http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:267576
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to