Skip to main content
July 23, 2009
Question

Related Selects

  • July 23, 2009
  • 1 reply
  • 535 views

I've been trying to follow this tutorial:

http://www.forta.com/blog/index.cfm/2007/5/31/ColdFusion-Ajax-Tutorial-2-Related-Selects

And I get can't it to work - my select boxes do not populate with anything. I've pretty much copied the code on the tutorial as much as I can (see code below), and I know my queries work - but I still can't get anything to display in the boxes. Any ideas on what to check?

CFC File (categories.cfc):

<cfcomponent output="false">
    <cffunction name="getTopLevel" access="remote" returnType="array">
        <cfset var result = ArrayNew(2)>
        <cfset var i = 0>
       
        <cfquery name="data" datasource="Photos">
            SELECT catID, description FROM pic_categories WHERE parentID = '-1' ORDER BY description ASC
        </cfquery>
       
        <cfloop index="i" from="1" to="#data.RecordCount#">
            <cfset result[1] = data.catID>
            <cfset result[2] = data.description>
        </cfloop>
       
        <cfreturn result>
    </cffunction>
    <cffunction name="getSecondLevel" access="remote" returnType="array">
        <cfargument name="topLevel" type="string" required="true">
       
        <cfset var result = ArrayNew(2)>
        <cfset var i = 0>
       
        <cfquery name="data" datasource="Photos">
            SELECT catID, description FROM pic_categories WHERE parentid = '#arguments.topLevel#' ORDER BY description
        </cfquery>
       
        <cfloop index="i" from="1" to="#data.RecordCount#">
            <cfset result[1] = data.catID>
            <cfset result[2] = data.description>
        </cfloop>
       
        <cfreturn result>
    </cffunction>
</cfcomponent>

Form Code:

<cfselect name="topLevel" bind="cfc:categories.getTopLevel()" bindonload="true" /><br />
<cfselect name="secondLevel" bind="cfc:categories.getSecondLevel({topLevel})" bindonload="true" />
    This topic has been closed for replies.

    1 reply

    Dileep_NR
    Inspiring
    July 24, 2009

    Hi

    try after removing  "bindonload="true" from "secondLevel"

    <cfselect name="secondLevel" bind="cfc:categories.getSecondLevel({topLevel})"  />