[color gray]<!--- this query will get the data to populate the select box--->[/color] <cfquery datasource="#datasource#" name="qSelectData">
SELECT Item, Value
FROM ItemTable
ORDER BY Item
</cfquery>
[color gray]<!--- Create a variable to use as the value you want to select. this could be the value of a seperate query, session variable, form variable, or anything you wish to compair. --->[/color] <cfset defaultValue = "mySelectedItem">
<select name="ItemMenu">
<option value="">Choose Item</option>
<cfoutput query="qSelectData">
[color gray]<!--- Inside the option tag check to see
if the value of the loop is the value
you want to display. --->[/color] <option value="#Value#"
[color red]<cfif qSelectData.Value eq defaultValue>
Selected
</cfif>[/color]
>#Item#</option>
</cfoutput>
</select>
If the values in the <cfif>...</cfif> match the produced output will look something like:
<option value = "mySelectedItem" selected>item</option>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.