ColdFuison - Creating a dynamic drop down within a <cfoutput> tag

I'm needing to create a dynamic select box by processing a query within  a large <CFOUTPUT> tag. I keep getting an error in the creationof my dynamic select box. Is there another way to get this done or a way to make this current code work?
<cfquery name="getReasons" datasource="#dbname#" username="#dbuser#" password="#dbpw#">
SELECT ON_HOLD_REASON
FROM OPTIONS_ON_HOLD_REASONS_MISSED
</cfquery>	
 
 
<cfoutput>
<!---Many lines of code--->
 
<!---Creation of 'On Hold Reasons'--->	
<select name="onHoldReason" id="onHoldReason">
	<option selected="selected" value="0">Please Select a Reason</option>	
	<cfoutput query="getReasons"><!---Needing help here--->
	<option value="#getReasons.ON_HOLD_REASON#" >#getReasons.ON_HOLD_REASON#</option>
	</cfoutput>
</select>
	
<!---Many lines of code ---> 
	</cfoutput>

Open in new window

WirtAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_agx_Commented:
The syntax looks correct.  Perhaps you are getting an error because of the nesting of cfoutput tags?

One option is to try changing the inner cfoutput to a cfloop

<cfoutput>
...
<select name="onHoldReason" id="onHoldReason">
        <option selected="selected" value="0">Please Select a Reason</option>  
        <cfloop query="getReasons"><!---Needing help here--->
        <option value="#getReasons.ON_HOLD_REASON#" >#getReasons.ON_HOLD_REASON#</option>
        </cfloop>
</select>
...
</cfoutput>

Or if you're using a cfform you could try using a cfselect tag, with the "query" attribute instead.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WirtAuthor Commented:
Thank you!!!
0
erikTsomikSystem Architect, CF programmer Commented:
OK. what you can do is this. Make sure the datasourse is valid. Check the application.cfm make sure that dbname is valid varible that stores your datasourse

2. try to rewrite your code as follow


<cfquery name="getReasons" datasource="#dbname#" username="#dbuser#" password="#dbpw#">
SELECT ON_HOLD_REASON
FROM OPTIONS_ON_HOLD_REASONS_MISSED
</cfquery>      
 
 
 
<!---Many lines of code--->
 
<!---Creation of 'On Hold Reasons'--->  
<select name="onHoldReason" id="onHoldReason">
        <option selected="selected" value="0">Please Select a Reason</option>   
        <cfoutput query="getReasons"><!---Needing help here--->
        <option value="#getReasons.ON_HOLD_REASON#" >#getReasons.ON_HOLD_REASON#</option>
        </cfoutput>
</select>
        
<!---Many lines of code ---> 
     

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.