Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default value for a Dynamic Select Box 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi Folks,

I'm new to ColdFusion, and i'm looking for some help on selecting a default value for a dynamic select box.

I have populated a select box with a query. The drop down lists displays a list of IDs. I have another query which selects one of these IDs. I want the drop down box to default to the selected ID.

this is the code i tried, which success. it always defaulted to the first row of the query

<SELECT name=&quot;courseid&quot;>
<CFOUTPUT query=&quot;getcourses&quot;>
<OPTION value=&quot;#getstudentdetails.courseid#&quot;>#getcourses.courseid#
</CFOUTPUT>
</SELECT>

getcourse is the list of IDs. getstudentdetails is the query which returns just one ID. Am I close?

Regards,
Peter
 
I do it like this:

<SELECT name=&quot;courseid&quot;>
<CFOUTPUT query=&quot;getcourses&quot;>
<OPTION value=&quot;#getstudentdetails.courseid#&quot; <CFIF #getstudentdetails.courseid# EQ #previouschoice#>Selected</CFIF> >#getcourses.courseid#
</CFOUTPUT>
</SELECT>


Works for me. Just replace #previouschoice# with whatever variable holds the previous choice.

Have fun...


 
Same concept, different method using #IIF()#

<SELECT name=&quot;courseid&quot;>
<CFOUTPUT query=&quot;getcourses&quot;>
<OPTION value=&quot;#getstudentdetails.courseid#&quot;
#IIF(#getstudentdetails.courseid# EQ #previouschoice#,DE('Selected'),DE(''))#>#getcourses.courseid#
</CFOUTPUT>
</SELECT>
- tleish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top