Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cfc bind

Guest
Apr 06, 2010 Apr 06, 2010

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>

440
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 06, 2010 Apr 06, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 07, 2010 Apr 07, 2010
LATEST

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources