This code works fairly well, so I wanted to share it.

It does have one small problem that I was wondering if someone could help me
with.

Problem: By using the back button on the browser, you can actually select
"Choose a Sub Category" (in the second select list) which submits the form and
throws an error on the following page which attempts to use the FORM.CatSub
variable for the final query....

For some reason using:

<cfparam name="FORM.CatSub" default="1">

at the top of the next page does NOT work, but using (to reload the original
select):

<cfif Form.CatSub EQ "">
<cflocation url = "/index.cfm">
</cfif>

does...

It seems a little convoluted, and I was wondering of someone could help me
clean it up.

The main dynamic dependant drop down code...


<cfquery name="rsCatMain" datasource="DB"
cachedwithin="#CreateTimeSpan(1,0,0,0)#">
SELECT * FROM CatMain
</cfquery>

<cfform name="CatMain" method="post" action="">
<cfselect onChange="submit()" name="CatMain">
<cfif Form.CatMain EQ "">
<option value="" selected>Choose a Main Category</option>
</cfif>
<cfoutput query="rsCatMain">
<cfif IsDefined ("Form.CatMain") AND #Form.CatMain# EQ
#form_cat_main_id#>
<option value="#cat_main_id#" selected>#form_cat_main#</option>
<cfelse>
<option value="#cat_main_id#">#cat_main_name#</option>
</cfif>
</cfoutput>
</cfselect>
</cfform>


<cfif IsDefined("Form.CatMain") AND #Form.CatMain# NEQ "">

<cfquery name="rsCatSub" datasource="DB"
cachedwithin="#CreateTimeSpan(1,0,0,0)#">
SELECT * FROM CatSub WHERE cat_main_id = #Form.CatMain#
</cfquery>

<cfform name="CatSub" method="post" action="">
<cfselect onChange="submit()" name="CatSub">
<option value="">Choose a Sub Category</option>
<cfoutput query="rsCatSub">
<option value="#cat_sub_id#">#cat_sub_name#</option>
</cfoutput>
</cfselect>
</cfform>

</cfif>