How can I populate and select value in select form field populated from query?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Haitashi
    New Member
    • Jun 2007
    • 96

    How can I populate and select value in select form field populated from query?

    Snippet:
    Code:
    <form>
    	<select name="secCode" id="secCode">
    		<cfloop query="Request.qSecCodes">	
    	<option value="#Request.qSecCodes.org_name#" <cfif (Request.qSecCodes.org_code EQ Variables.oSurvey.secCode)>selected="true"</cfif>>#Request.qSecCodes.org_name#</option>
    		</cfloop>
    	</select>
    </form>
    As you can see, I'm populating that select with the results of a query. I wanted to have a value selected by default. That's what the CFIF was put there for. I wanted the selected value to default to something specific when that value in Request.qSecCod es.org_code is the same as in Variables.oSurv ey.secCode.

    This was kind of hard to explain. I hope I'm clear enough.
  • Haitashi
    New Member
    • Jun 2007
    • 96

    #2
    I realized my problem (why isn't the selected thing working).

    So, the query gets the sec_code and org_name. Codes have a one to one relationship to names. In other words, the name is the human readable format and the code, well, its code.

    Now, the select should display the org_name. But pass the sec_code value. So if a user selects ORGANIZATION_A, then the form will submit the value "ORGA" for the secCode.

    Don't know if this is html or coldfusion logic I have to work with.

    As always, help is greatly appreciated.
    Last edited by Haitashi; Nov 10 '08, 04:16 PM. Reason: Spelling errors...

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      You just need to set the value of each option to the code instead of the name.

      Comment

      • Haitashi
        New Member
        • Jun 2007
        • 96

        #4
        You are correct sir!

        *feels silly

        Sometimes when you look at code long enough it stops making sense =P

        Thanks!

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Don't worry. We've all been there!

          Glad to see that you got it working.

          Comment

          Working...