Skip to main content
April 6, 2010
Question

cfc bind

  • April 6, 2010
  • 1 reply
  • 479 views

I am trying to do a cfselect with bindonload with passing an optional parameter but i can't seem to get it to work, does anyone know if this is even possible or what i'm doing wrong. Any help is very much appreciated.

---------------------user.cfc------------------------------

    <cffunction name="getStates" access="remote" returntype="array">
      <cfargument name="customerState" type="string" required="no">
     
      <cfset var getStateList="">
      <cfset var result=ArrayNew(2)>
      <cfset var i=0>
  
       <!---Get data --->
      <cfquery name="getStateList" datasource="#application.dsn#">
      SELECT DISTINCT state
      FROM tbl_zips
      ORDER BY state
      </cfquery>
     
      <!--- Convert results to array --->
      <cfloop index="i" from="1" to="#getStateList.RecordCount#">
         <cfset result[1]=getStateList.state>
         <cfset result[2]=getStateList.state>
      </cfloop>
  
      <cfif isDefined("arguments.customerState")>
       <cfset ArrayPrepend(result[1][1],#arguments.customerState#)>
       <cfset ArrayPrepend(result[1][2],#arguments.customerState#)>
      </cfif>


          <cfreturn result>

    </cffunction>

==================Form================

<cfform action="test.cfm" method="post">

<table align="center">

    <tr>
     <td>
         <cfif isDefined("customer.state")>
              <cfselect name="state" bind="cfc:cfc.user.getStates({customer.state})" bindonload="true"/>
            <cfelse>
             <cfselect name="state" bind="cfc:cfc.user.getStates()" bindonload="true"/>
            </cfif>
        </td>
    </tr>
</table>
</cfform>

    This topic has been closed for replies.

    1 reply

    Fernis
    Inspiring
    April 6, 2010

    Since you're not binding to a form field value, forget the { }.

    <cfselect name="state"  bind="cfc:cfc.user.getStates('#customer.state#')" bindonload="true"/>

    should work nicely.

    --

    -Fernis - fernis.net - ColdFusion Developer For Hire

    April 7, 2010

    Cool, thnx that worked!!!

    Also is possible to be able to specifiy one of the elements being passed back to the cfselect bind to be selected onload?