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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic dropdown (SELECT) and pre-selected

Status
Not open for further replies.

mikeali

Programmer
Nov 14, 2004
16
US
I have multiple dropdown menus in a page. All these dropdowns are populating from a SQL Table. When user select a value for a particular dropdown I save that in a different table. Now I want to make the "already selected" value to be "selected" on the dropdown menu. Notice that I have 2 tables and dropdowns.

Here is little draft:

Table A
data for dropdown

Table B
data for saved dropdown

DropDown



Here is the actual dropdown:

<SELECT name="Dd3">

<CFOUTPUT query="GetDd3">
<OPTION value="#RecNum#">#Title#</OPTION>
</CFOUTPUT>

</SELECT>

Thank you in advanced for helping me with this problem.
 
This should be what you're looking for: faq232-4780



Hope This Helps!

Ecobb
Beer Consumption Analyst

"My work is a game, a very serious game." - M.C. Escher
 
Thanks Ecobb for the fast reply.

The problem is i don't know how to create that defaultvalue portion. Note that "Table B" has more than one row.

May be I should loop through Table B and store the values into a single variable like: defaultvalue = 1,2,4,5,6,7,.

This case if i can search through defaultvalue and if the listvalue EQ to defaultvalue-result then that particular option is selected.

What do you think?

Thanks,

Mike
 
You'll have 4 queries. 2 queries get the data to populate the data in the drop down boxes. the other two (or one depending on how you write the query) will get the default selected value

<cfquery name = "q1">
get data for DD1
</cfquery>
<cfquery name = "q2">
get data for DD2
</cfquery>
<cfquery name = "a1">
get data for answer1
</cfquery>
<cfquery name = "a2">
get data for answer2
</cfquery>

<select name = "dd1">
<option value = ""></option>
<cfoutput query = "q1>
<option value = "#q1.fieldName# <cfif q1.fieldName eq a1.fieldName>Selected</cfif>">#q1.fieldName#</option>
</cfoutput>
</select>

do that for both drop downs.


A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-Douglas Adams (1952-2001)
 
oops. issues with my quotes

<option value = "#q1.fieldName#" <cfif q1.fieldName eq a1.fieldName>Selected</cfif>>#q1.fieldName#</option>


A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-Douglas Adams (1952-2001)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top