Skip to main content
June 8, 2009
Question

cfselect bindings

  • June 8, 2009
  • 1 reply
  • 1377 views

I am trying to do a bind with a cfselect, below is the code i have so far:

Queries.cfc

<cfcomponent>

    <cffunction name="getStates" access="remote" returntype="array" output="no">

      <cfset var data="">
      <cfset var result=ArrayNew(2)>
      <cfset var i=0>

     
      <cfquery name="data" datasource="#request.dsn#">
      SELECT abbr,state
      FROM tbl_zips

      </cfquery>


      <cfloop index="i" from="1" to="#data.RecordCount#">
         <cfset result[1]=data.abbr>
         <cfset result[2]=data.state>
      </cfloop>

      <cfreturn result>
    </cffunction>
</cfcomponent>

================================================================================

test.cfm

<cfform name="testForm" action="" method="post">

<cfselect name="state" bind="cfc:cfc.Queries.getStates()" bindonload="true"/>

</cfform>

When i run the test.cfm file, the drop down never populates. I also turned on debugging and i don't even see it trying to call the CFC. But if i manually invoke the component using cfinvoke, it grabs the data.

Has anyone ever come across this issue before?

This topic has been closed for replies.

1 reply

June 9, 2009

Here's something else i found out, whenever i try to do a bind using cfselect i don't even see it calling the cfc using the debugger, but i can call the cfc all day manually invoking it, has anyone seen this happen before?

June 10, 2009

OK, i give up with cfc bindings. Would it be possible to maybe have a javascript function call a cfc based on the onchange event from a select box?

So as soon as they choose a state, it will automatically call the cfc with the state as the argument and then populate the next select box, of cities in that state.

June 10, 2009

Sure it is possible.  It is not that difficult to roll your own AJAX functionality.  You just write a basic JavaScript function that use the XMLHttpRequest object that will make a HTTP request and expect XML returned.  (Amazing how they name these functions isn't it.).

Here is the first thing that turned up for me on a Google Search for AJAX.

http://www.w3schools.com/Ajax/Default.Asp

Then your CFC just needs to return the data in the proper format whenever it receives a request.

HTH

Ian


I like your idea alot, i will definitely go that route. Do you know where i could find a very simple example on how to do something like this?