I do this with frames. The main frame contains your form which I'll call
"main", the other frame is given 0 size (so that the user does not see it)
and I'll call it "top".
I'm grabbing some code to donate, but it's a heavily modified and
simplified version of the only thing that's readily available to me right
now - I would be surprised if it ran without some debugging, but hope you
will find it helpful. Let me know if you need help getting it to run.
You'll need to either add some error control in case your subRegions query
returns 0 records or only select choices from regions where a subRegion
definitely does exist for that particular region.
Be aware, that if for some reason the subRegion template fails to run and
you do a validation on subRegions when submitted, your user might be left
stranded.
I'm going to assume your database structure is similar to:
region.regionID, region.name
subRegion.regionID, subRegion.name
where subRegion.regionID is a foreign key for region.regionID
==================
In the main frame:
==================
<script language=javascript>
<!--
function removeAllOptions(obj) {
obj.options.length=1;
obj.options[0] = new Option("------------","NULL");
obj.selectedIndex=0;
}
function loadingMessage(obj) {
obj.optionslength=1;
obj.options[0] = new Option("-- Loading, please wait --","NULL");
obj.selectedIndex=0;
}
function loadSubRegions(regionID) {
removeAllOptions(document.regionForm.subRegions);
if ( regionID <> "NULL" ) {
loadingMessage(document.regionForm.subRegions);
self.open("www.yourdomain.com/buildSubRegions.cfm?regionID="
+ regionID,"top");
}
}
function copyOptions(src,dest) {
for (i=0;i<src.length;i++) {
dest.options[i] = new
Option(src.options[i].text,src.options[i].value);
}
}
function CO() {
copyOptions(parent.top.document.localForm.dynaDropDown,
document.regionForm.subRegions);
}
// -->
</script>
<cfquery name=regionQuery>
SELECT regionID, name
FROM regions
ORDER BY name
</cfquery>
<form name=regionForm method=post>
<select name=regions
onChange=loadSubRegions(this.options[this.selectedIndex].value)>
<option value="NULL">-- CHOOSE ONE --
<cfoutput query=regionQuery><option
value="#regionID#">#name#</cfoutput>
</select>
<select name=subRegions><option value="NULL">------------</select>
</form>
=====================
buildSubRegions.cfm:
=====================
<cfquery name="getTable">
SELECT name
FROM subRegions
WHERE regionID = #url.regionID#
ORDER BY name
</cfquery>
<form name="localForm">
<select name="dynaDropDown">
<option value="NULL">-- CHOOSE ONE --
<cfoutput query="getTable">
<option value="#name#">#name#
</cfoutput>
</select>
</form>
<script language="javascript">
parent.main.CO();
</script>
At 4/4/2002 08:56 PM, you wrote:
>I am trying to find some code similar to one often used on auto parts
>and other large drill down lists.. I have two select lists... Regions
>and subregions... In the form I would like to have the regions chosen
>first, and then upon the release of the chosen one, it would refresh the
>page showing the next set of options for subregions (of course the list
>of subregions would have taken the regions value to find the appropriate
>list of subregion values.)
>
>Anyone have any suggestions
>
>Thanks
>
>Colin Wilson
>
>---
>Outgoing mail is certified Virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.324 / Virus Database: 181 - Release Date: 14/02/2002
>
>
>
>-------------------------------------------------------------------------
>This email server is running an evaluation copy of the MailShield anti-
>spam software. Please contact your email administrator if you have any
>questions about this message. MailShield product info: www.mailshield.com
>
>-----------------------------------------------
>To post, send email to [EMAIL PROTECTED]
>To subscribe / unsubscribe: http://www.dfwcfug.org
-------------------------------------------------------------------------
This email server is running an evaluation copy of the MailShield anti-
spam software. Please contact your email administrator if you have any
questions about this message. MailShield product info: www.mailshield.com
-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org