select/bind help
I'm helping a colleague with a web app that is basically a database of links to documents that are scattered around our website. It's meant to be a way to search for documents using various criteria without having to browse the entire site.
The data is organized into categories (known as disciplines) and subcategories (known as subdisciplines) as well as a few other parameters. I'm helping to get the database normalized, but one of the things I want to do is make the search form reflect the current database contents.
Currently, a web form with a few <select> items is used, and some Javascript makes the subdisciplines <select> dependent on what's selected in the disciplines <select> box. Thus, anytime a new one of either of those two items is added, the JS needs to be edited. I'd like to make this automatic, so I'm trying to use bind to do it.
Right now I have the following form:
<cfform name="fectchdocs" action="#CGI.SCRIPT_NAME#" method="post">
<p><label for="disc">Discipline:</label><br />
<select name="disc" id="disc">
<option value="">All</option>
<cfoutput query="GetDisc">
<option value="#disc_id#"<cfif FORM.disc eq disc_id> selected="selected"</cfif>>#adiscipline#</option></cfoutput>
</select></p>
<p><label for="subdisc">Subdiscipline:</label><br />
<cfselect name="subdisc" id="subdisc" bindonload="Yes" bind="cfc:searchdata.getSubs({discs})" /></p>
<p><input type="select" name="search" value="Search" /></p>
</cfform>
And the following CFC (searchform.cfc):
<cfcomponent output="false">
<cffunction name="getDiscs" access="remote" returntype="array">
<cfquery name="discs" datasource="guidance">
SELECT disc_id, adiscipline
FROM search_fhwa_disc
ORDER BY adiscipline
</cfquery>
<cfset count="1" />
<cfset results = arraynew(2)>
<cfloop query="discs">
<cfset results[count][1]="#disc_id#" />
<cfset results[count][2]="#adiscipline#" />
<cfset count= count+1>
</cfloop>
<cfreturn results />
</cffunction>
<cffunction name="getSubs" access="remote" returntype="array">
<cfargument name="disc_id" type="string" required="true">
<cfquery name="subs" datasource="guidance">
SELECT sub_id, bsubdiscipline
FROM search_fhwa_sub
WHERE parent_id = <cfqueryparam value="#arguments.disc_id#" cfsqltype="cf_sql_numeric">
ORDER BY bsubdiscipline
</cfquery>
<cfset count="1" />
<cfset results = arraynew(2)>
<cfloop query="subs">
<cfset results[count][1]="#sub_id#" />
<cfset results[count][2]="#bsubdiscipline#" />
<cfset count= count+1>
</cfloop>
<cfreturn results />
</cffunction>
</cfcomponent>
It of course fails miserable with three popup errors. A bind error telling me 'discs' is not found. A second 'discs' not found error, and one about passing a null value to my query.
It's obvious that I'm using the wrong function/variable name somewhere, but I'm not sure where.
I know that the CFC works, because if I invoke either method, I get the array that I expect when I dump the returnvariable.