2 Replies Latest reply: Jun 9, 2012 5:13 AM by akaBobo RSS

    Option value with cfselect in CF10

    akaBobo Community Member

      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.

        • 1. Re: Option value with cfselect in CF10
          BKBK MVP

          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>

          • 2. Re: Option value with cfselect in CF10
            akaBobo Community Member

            Ok, thanks.  It appears that the livedocs just need some editing as that is where I pulled that example from:

             

            http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_r-s_14.html

             

            Granted, it is CF8/CF9, but I tried this method on CF8 and it didn't work either.

             

            I went ahead and created a union in query to add the rows, which is probably the better solution anyway.