Skip navigation
akaBobo
Currently Being Moderated

Option value with cfselect in CF10

Jun 8, 2012 8:55 AM

Has anyone gotten <option> values to work with cfselet in CF10?

 

This example:

 

<cfform name="mycfform">

    <!--- 

        The States selector. 

        The bindonload attribute is required to fill the selector. 

    --->

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

        <option name="0">--state--</option>

    </cfselect>

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

        <option name="0">--city--</option>

    </cfselect>

</cfform>

 

When adding the option value, it doesn't show up in CF10.

 
Replies
  • Currently Being Moderated
    Jun 9, 2012 2:55 AM   in reply to akaBobo

    By design, ColdFusion's binding apparatus actually takes over the task of populating the list of options. Your option tag does not come in through the bind. Hence, as far as binding is concerned, your option tag does not exist.

     

    The solution is to include the first option, for example, '--state--', in the return value of the bind. That is precisely what is done in the Coldfusion documentation. See the example bindFcns.cfc in the documentation on cfselect. There you will find:

     

    <cffunction name="getstates" access="remote">

    <!--- I added the var--->

    <cfset var state = arraynew(2)>

    <cfset var xmlData = getXmlData()>

    <cfset var numStates = 0>

    <cfset state[1][1] = "0">

    <cfset state[1][2] = "--state--">

    <cfset numStates = ArrayLen(xmlData.states.XmlChildren)>

    <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)>

    </cfloop>

    <cfreturn state>

    </cffunction>

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points