• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

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

0
Wirt
Asked:
Wirt
1 Solution
 
_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
 
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now