1 Reply Latest reply on May 17, 2014 2:20 PM by BKBK

    cf9 cfselect bind


      I have multiple dropdown lists on a form that are interdependent on each other. So, I'm using cfselects with binding based on selection of the previous drop down.


      Here's the scenario:

      Each 'sales representative' is assigned a number of clients. In turn, the clients are assigned a designated customer service rep.


      I have a form that is using a cfselect to bind the clients displayed in the client list based on which sales representative is selected.


      Once the 'client' is selected, I would like the next drop down list to populate with all customer service reps but have the rep that is actually assigned to the client be the default selected item in the drop down (e.g., selected="selected"). I need all service reps listed because there are instances that a case will be assigned to a different service rep than the default.


      I have scoured the web and reviewed many examples but am still at a loss.


      In my research found something similar to the code I'm using in the cfc (below) to pull the a list of all service reps and compare to see if the rep id is the client's designated rep.


      <cfset result[i+1][3]=true> is being populated correctly, however this does not carry over to my cfselect to indicate the item selected.


      Is there a different way I need to go about this?


      Please ask if I'm not being clear in what I need this to do.


      THANKS in advance for any assistance!



      Code snippet:


      <cffunction name="getSvcReps" access="remote" returnType="array">

        <cfargument name="clientId" type="any" required="yes">

        <cfargument name="dsn" type="any" required="yes">


        <!---defines variables--->

        <cfset var data="">

        <cfset var result=ArrayNew(2)>

        <cfset var i=0>

        <cfif not len(arguments.clientId)>

        <cfset result[1][1]="">

        <cfset result[1][2]="Please select a Client--->">

        <cfreturn result>


        <cfquery datasource="#arguments.dsn#" name="svcReps">



        ,CONCAT(first," ",last) as svc_rep_name





        <cfquery datasource="#arguments.dsn#" name="defaultSvcRep">






        client_id ='#arguments.clientId#'

        and rep_type="svc"



        <!---convert results to array--->

        <cfset result[1][1]="">

        <cfset result[1][2]="Select a Service Representative--->">

        <cfset result[1][3]="">

        <cfloop index="i" from = "1" to="#svcReps.recordCount#">

        <cfset result[i+1][1]=svcReps.service_rep_id[i]>

        <cfset result[i+1][2]=svcReps.svc_rep_name[i]>

        <cfif svcReps.service_rep_id[i] EQ defaultSvcRep.rep_id>

        <cfset result[i+1][3]=true>


        <cfset result[i+1][3]="">





        <cfreturn result>



        • 1. Re: cf9 cfselect bind
          BKBK Adobe Community Professional & MVP

          Adobe's documentation on cfselect contains a useful example. I have modified it to suit your needs.


          Just copy the following 3 files into the same directory, and run testPage.cfm.



          <cfform name="mycfform">

              <cfselect name="state" bind="cfc:bindFcns.getstates()" bindonload="true" >


              <cfselect name="city" bind="cfc:bindFcns.getcities({state})">





          <cffunction name="getXmlData" output="false" returntype="xml" access="private">
              <cfset var xmlData = "">
              <cffile action="read" file="#expandpath('.')#\states.xml" variable="xmlData">
              <cfset xmlData = XmlParse(xmlData)>
              <cfreturn xmlData>


          <cffunction name="getStates" access="remote" returntype="array">
              <cfset var state = arraynew(2)>
              <cfset var xmlData = getXmlData()>
              <cfset var numStates = 0>


              <cfset numStates = ArrayLen(xmlData.states.XmlChildren)>
             <cfset state[1][1] = "">
              <cfset state[1][2] = "== State ==">
              <cfloop from="1" to="#numStates#" index="j">
                  <cfset state[j+1][1] = ltrim(xmlData.states.state[j].XmlAttributes.abr)>
                  <cfset state[j+1][2] = ltrim(xmlData.states.state[j].name.xmlText)>
              <cfreturn state>


          <cffunction name="getCities" access="remote" returntype="array">
              <cfargument name="state" required="yes">
              <cfset var city = arraynew(2)>
              <cfset var xmlData = getXmlData()>
              <cfset var numStates = 0>
              <cfset var numCities = 0>


                  <cfset numStates = ArrayLen(xmlData.states.XmlChildren)>
             <cfset city[1][1] = "">
                  <cfset city[1][2] = "== City ==">
                  <cfloop from="1" to="#numStates#" index="j">
                      <cfif xmlData.states.state[j].XmlAttributes.abr eq state>
                          <cfset numCities = ArrayLen(xmlData.states.state[j].cities.XmlChildren)>
                          <cfloop from="1" to="#numCities#" index="k">
                              <cfset city[k+1][1] =ltrim(xmlData.states.state[j].cities.city[k].XmlAttributes.name)>
                              <cfset city[k+1][2] = ltrim(xmlData.states.state[j].cities.city[k].XmlAttributes.name)>
              <cfcatch type="any">
                  <cfdump var="#cfcatch#">
              <cfreturn city>






              <state abr="NJ">

                  <name>New Jersey</name>


                      <city name="Edison" />

                      <city name="Rahway" />

                      <city name="Atlantic City" />

                      <city name="Hoboken" />

                      <city name="Jersey City" />

                      <city name="Newark" />

                      <city name="Trenton" />

                      <city name="Union City" />



              <state abr="CA">



                      <city name="Anaheim" />

                      <city name="Beverly Hills" />

                      <city name="Elk Grove" />

                      <city name="Fairfield" />

                      <city name="Fremont" />

                      <city name="Indian Wells" />

                      <city name="Long Beach" />



              <state abr="ME">



                      <city name="Augusta" />



              <state abr="MA">



                      <city name="Boston" />

                      <city name="Cambridge" />