Looks like I'm set to make a pest of myself today. *grin*
This problem is a tad more complicated. I have a form by which records in the
database can be edited. Each record has to belong to a Section, with each
Section belonging to a Subcategory (which in turn each belong to a Category,
but that is neither here nor there). Because there are about 20 Subcategories,
and each of these holds between 5 and 15 Sections, I decided that to simply
list them all in one dropdown would be far too lengthy. Far better to have a
system of two related select boxes so the user can pick the Subcategory from
the first and then select from only a list of Sections belonging to that
Subcategory (it also reduces the risk of confusing the system by having them
choose unrelated Subcategories and Sections).
So far so good, and everything works just dandy on the "Add" page. On
the "Edit" page, however, things aren't so rosy. The two related selects method
I am using is the one that involves resubmitting the form to itself to populate
the second select - I liked this one because it kept formatting the content of
the two select boxes much simpler than it was using the TwoSelectsRelated
custom tag.
The problem I have is getting the query for the second box (Sections) to filter
itself properly. I have a generic query which I am using to build the
recordset, and am using some conditional logic at the front of it to work out
how to filter it. This is what it looks like so far:
<cfoutput>
<cfif IsDefined("URL.ID") AND #URL.fuseaction# NEQ "admin.editProduct">
<cfset ID = "#URL.ID#">
<cfelseif IsDefined("page.SubcategoryID")>
<cfset ID = "#SubcategoryID#">
<cfelseif NOT IsDefined("page.SubcategoryID") AND #URL.fuseaction#
EQ "admin.editProduct">
<cfset ID = "#qry_getThisProduct.SubcategoryID#">
<cfelse>
<cfset ID = "#qry_GetAllSubcategories.ID#">
</cfif>
</cfoutput>
<cfquery name="qry_GetAllSections" datasource="#session.dsn#">
SELECT *
FROM Section
WHERE SubcategoryID = #ID#
</cfquery>
The second condition is from the two related selects method. The third is what
I have tried to do to make the code work properly in the "Edit" page.
Here is how it is outputting:
<th><label for="SubcategoryID">Subcategory</label></th>
<td>
<select name="SubcategoryID" onchange="this.form.submit()">
<option>Select a Subcategory</option>
<cfloop query="qry_GetAllCategories">
<option>-- #UCase(qry_GetAllCategories.CategoryName)# --
</option>
<cfinclude
template="../_queries/qry_GetAllSubcategories.cfm">
<cfloop query="qry_GetAllSubcategories">
<option value="#qry_GetAllSubcategories.ID#"
<cfif isDefined('form.SubcategoryID')><cfif form.SubcategoryID
eq "#qry_GetAllSubcategories.ID#">selected</cfif><cfelse><cfif
qry_getThisProduct.SubcategoryID
EQ "#qry_GetAllSubcategories.ID#">selected</cfif></cfif>>#qry_GetAllSubcategorie
s.SubcategoryName#</option>
</cfloop>
</cfloop>
</select>
</td>
<th><label for="SectionID">Section</label></th>
<td>
<select name="SectionID">
<option>Select a Section</option>
<cfinclude template="../_queries/qry_GetAllSections.cfm">
<cfloop query="qry_GetAllSections">
<option value="#qry_GetAllSections.ID#" <cfif
#qry_GetThisProduct.SectionID#
EQ "#qry_GetAllSections.ID#">selected</cfif>>#qry_GetAllSections.SectionName#</o
ption>
</cfloop>
</select>
</td>
Hopefully this makes sense, what I'm doing? What is meant to happen is that
when the page comes up, it automatically populates the first select and selects
the option that is currently in the database. It then populates the second
select with the relevant Sections for that Subcategory and selects the one that
is in the database. If the user then decides to change the Subcategory, it
refreshes the page and repopulates the Sections box with the new set of
Sections.
What is happening is that it comes up fine when the user first gets to the
page, but if they select a different Subcategory it doesn't change the contents
of the second select box. The problem I seem to have is that it is not changing
the value of the SubcategoryID being passed to the query (I've tried outputting
it seperately and it doesn't change when a new Subcategory is selected).
Anyone got any ideas on this one?
Cheers,
Seona.
---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
Aussie Macromedia Developers: http://lists.daemon.com.au/