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

Preselecting in a multiselect box 1

Status
Not open for further replies.

profwannabe

Programmer
Jan 6, 2001
53
US
On an edit form I am trying to populate all the existing values of the record. This works for most of my form fields, including cfselects, except for my multiselect boxes. The values in the field are comma delimited. Not sure if I can loop through the list and have each value preselected, since the select code seems to imply a single result; in other words, it seems to me that I might be looping in such a way that generates multiple versions of the multiselect box, each of which has a different preselect from my list.

Any ideas on this? I am just starting to work with lists, so I may be missing something relatively basic in dealing with the values in my list as part of the query.

 
Hey Prof,

If I understand what you're trying to do, I think this will work.

<cfset myList = &quot;a,b,c,d&quot;>

<select name=&quot;var1&quot; multiple>
<cfloop index=&quot;x&quot; list=#myList#>
<cfoutput><option selected=&quot;yes&quot;>#x#</cfoutput>
</cfloop>
</select>

Let me know if it's not right,
GJ
 
Not quite, as presumably only some of the options would have been selected. Thus

<cfquery name=&quot;getSICCodes&quot; datasource=&quot;#datasource#&quot; dbtype=&quot;odbc&quot;>

SELECT CodeNumber, 'ListDisplay'=CodeNumber+': &quot;+CodeName
FROM Codes_SIC
ORDER BY CodeNumber

</cfquery>

<cfquery name=&quot;getClientInfo&quot; datasource=&quot;#datasource#&quot; dbtype=&quot;odbc&quot;>

SELECT SIC
FROM Clients
WHERE ClientID = #attributes.ClientID#

</cfquery>

<cfselect name=&quot;SIC&quot; value = &quot;CodeNumber&quot; display =&quot;ListDisplay&quot; multiple>

However, I think that your method points me to the right direction: use a cfif statement to see if the option value = #mylist#, select if so, otherwise do not select. What would be my cfif code, however? Not sure how the list information would compare to the SIC Codevalue generating the select options. Also, there are a few hundred SIC codes. Any chance this might be a problem?
 
Is this what you need?

<option<cfif listfind(myList,getSICCodes.ListDisplay) selected=&quot;yes&quot;</cfif>>
#getSICCodes.ListDisplay#

GJ
 
I think so. Not sure about ListFind, but I can read up on that one. Thanks once again for your help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top