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!

listfind & option selected

Status
Not open for further replies.

LongHorn

Programmer
Jun 20, 2001
30
US
I have a list L1 of (A,B,C,D,E,F,G) and a second list L2 of
(B,E,G). I want to display a select box of everything in list L1 but with all items in list L2 highlighted.
I don't know how to use Listfind function. The double quotes is where I'm confused.

Here is my code:

<cfset List2=ValueList(ProjTePrefix.proj_prefix)>
<cfset List1=ValueList(PrefixList.proj_type_code)> <cfset aPrefixes = ListtoArray(List1)>
<cfloop index=&quot;nLp&quot; from=&quot;1&quot; to=&quot;#ArrayLen(aPrefixes)#&quot;> <cfset attributes.prefix = aPrefixes[nLp]>
<select name=&quot;proj_prefix&quot; size=&quot;15&quot; multiple=&quot;multiple&quot;>
<option
<cfset found = ListFind(List2,&quot;#attributes.prefix#&quot;)>
<cfif found gt 0>
selected=&quot;selected&quot;> #attributes.prefix#
<cfelse>
value=&quot;#attributes.prefix#&quot;> #trim(attributes.prefix)#
</cfif>
</option></cfloop>
 
<cfset List2=ValueList(ProjTePrefix.proj_prefix)>
<cfset List1=ValueList(PrefixList.proj_type_code)>

<select name=&quot;yourselectbox&quot;>
<cfloop index=&quot;this&quot; list=&quot;#list1#&quot;>
<option value=&quot;#this#&quot; #iif(listfind(list2,this),de(&quot;selected&quot;),de(&quot;&quot;)>#this#
</cfloop>
</select>

HTH,
Phil Hegedusich
iimaksmall.gif
 
Thank you, Phil, but it didn't work.
I think you left off the closing parentheses and the pound sign in your iff statement.
Your code returns everything in List 1 but with nothing selected.
 
Absolutely right. Was typing fast and headed out the door.

Does it work with the pound sign and the closing parenthesis? Do the values in list1 match the values in list2, i.e., trimmed, same case, etc.?
 
Thank you very very much, Phil, that trim suggestion works like a charm.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top