update / insert records using a dynamic dropdown problem.
Hello;
I'm trying to write part of an app that has to use a dynamic dropdown for category selection. Right now, it's all written in coldfusion, and if I use a java script, to "submit the form" so the dropdown can see if there is a sumb cat attached to your selection, it kicks my page over to the action page, and I don't want a select function to do that, that's where the update / insert record code is. I'm trying to either make this dynamic dropdown work without reloading the page, or have it reload the page, but not submit the form if it's the select dropdown that was used.
Is that understandable?
I also tried some ajax that reloads a div tag, but that isn't working at all. I am attaching my coldfusion code. Maybe someone can help me think of a way to make this work? Or a web site with a tutorial on something like this?
The code:
<cfif isDefined('form.select_Main_Group')>
<cfset page.select_Main_Group = form.select_Main_Group>
</cfif>
<cfform action="merchAction.cfm" method="post" name="content" enctype="multipart/form-data">
<!--- all my form fields are here, just posting selects --->
<cfquery name="get_Main_Group" datasource="#APPLICATION.dataSource#">
SELECT DISTINCT merchCategory.CategoryID, merchCategory.CatName
FROM merchCategory
ORDER BY CatName
</cfquery>
<select name="select_Main_Group" required="yes" id="ajaxmenu" onChange="ajaxcombo('ajaxmenu', 'contentarea')">
<option>Select Main Group</option>
<cfloop query="get_Main_Group">
<option value="#CategoryID#" <cfif isDefined('form.select_Main_Group')><cfif form.select_Main_Group eq "#url.CategoryID#">selected</cfif></cfif>>#CatName#</option>
</cfloop>
</select>
<cfif isDefined('page.select_Main_Group')>
<!--- query DB for second drop down list, based on the selected item from the first list --->
<cfquery name="get_Sub_Group" datasource="#APPLICATION.dataSource#">
SELECT subID, subName, CategoryID
FROM merchSubCat
WHERE CategoryID = #page.select_Main_Group#
</cfquery>
<!--- second drop down list --->
<select name="select_Sub_Group" required="yes">
<option>Select Subgroup</option>
<!--- dynamically populate the second drop down list based on the get_Sub_Group query --->
<cfloop query="get_Sub_Group">
<option value="#subID#">#subName#</option>
</cfloop>
</select>
</cfif>
Can anyone help me out? I can add the ajax code if needed, or java that I've tried or am trying. But there has to be a better way.
Thank you.
