Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Haitashi's Avatar
Member
 
Join Date: Jun 2007
Location: Orlando, FL
Posts: 94
#1: Nov 10 '08
Snippet:
Expand|Select|Wrap|Line Numbers
  1. <form>
  2.     <select name="secCode" id="secCode">
  3.         <cfloop query="Request.qSecCodes">    
  4.     <option value="#Request.qSecCodes.org_name#" <cfif (Request.qSecCodes.org_code EQ Variables.oSurvey.secCode)>selected="true"</cfif>>#Request.qSecCodes.org_name#</option>
  5.         </cfloop>
  6.     </select>
  7. </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.qSecCodes.org_code is the same as in Variables.oSurvey.secCode.

This was kind of hard to explain. I hope I'm clear enough.

Haitashi's Avatar
Member
 
Join Date: Jun 2007
Location: Orlando, FL
Posts: 94
#2: Nov 10 '08

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


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.
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#3: Nov 11 '08

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


You just need to set the value of each option to the code instead of the name.
Haitashi's Avatar
Member
 
Join Date: Jun 2007
Location: Orlando, FL
Posts: 94
#4: Nov 17 '08

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


You are correct sir!

*feels silly

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

Thanks!
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#5: Nov 17 '08

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


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

Glad to see that you got it working.
Reply