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

Selecting Multiple items from a List(CFSELECT) on load?

Status
Not open for further replies.

wmd3

Programmer
Jan 22, 2002
37
US
Hi,

I am trying to select multiple items from a list on the load of a page. The list is loaded like the following:
Code:
<CFSELECT NAME=&quot;lstName&quot; QUERY=&quot;QueryName&quot; SIZE=6 MULTIPLE />
If I select only one item it works.
Code:
<CFSELECT NAME=&quot;lstName&quot; QUERY=&quot;QueryName&quot; SIZE=6 MULTIPLE SELECTED=&quot;ValueToBeSelected&quot; />
But, I can't find a way to select multiple items from the start. I have tried using a comma-delimited list, but that didn't work.

Any idea's?

Thanks.
- Bill
 

I believe you'd have to use javascript to select the multiple items (ie - I don't believe there's a way to do it from within the tag).

-Carl
 
That is what I have eventually done, Carl.

Here is my code if anyone else has the same problem.
Code:
<CFOUTPUT>
    <CFSelect NAME=&quot;lstName&quot;
        query=&quot;queryName&quot;
        value=&quot;valueColumn&quot;
        display=&quot;displayColumn&quot;
        size=14
        multiple
    />

    <script language=javascript>
        var temp = '#ValueList#';
        var list = temp.split(',');
        var opt = document.all.lstName.options;
        for(var i = 0; i < list.length; i++)
        {
            for(var j = 0; j < opt.length; j++)
            {
                if(opt[j].value == list[i])
                {
                    opt[j].selected = true;
                }
            }
        }
    </script>
</CFOUTPUT>
Thanks for your response Carl.
 
Glad you got it working. Though I don't know where my head was yesterday... you could do the same thing server-side if you just used a standard SELECT to build the list yourself, rather than using a CFSELECT:
Code:
<select name=&quot;lstName&quot; multiple=&quot;multiple&quot;>
    <CFOUTPUT query=&quot;queryName&quot;>
       <CFIF ListFindNoCase(&quot;#mySelectedValues#&quot;,someField) GT 0><option value=&quot;#someField#&quot; selected=&quot;selected&quot;><CFELSE><option value=&quot;#someField#&quot;></CFIF>#SomeOtherField#</option>
    </CFOUTPUT>
</select>
if you ever want to break free of javascript ;-)

-Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top