Search code examples
coldfusionmulti-selectcoldfusion-8

Coldfusion Multi-Select box without CFSelect


How would one go about building a multiselect box in Coldfusion without using CFForm or CFSelect?

This is to pull values from a DB so its not just a static select box it is dynamic.

This is my first time every trying to code in ColdFusion, I have always been a .Net person so this is a bit of a change for me.

The reason why I am needing this is because I've gotten hired into a department at work that uses Coldfusion but from what the Lead developer told me is they do not use CFForm and seeing as how CFSelect requires to be inside CFForm I need a different way of doing this.


Solution

  • Use plain old HTML, for example:

    <cfquery name="qryUsers" datasource="datasourcename"> 
        SELECT [User].[UserID], [User].[FirstName] 
        FROM [User]
    </cfquery>
    
    
    <cfoutput>
        <form ...>
            <select name="users" multiple="multiple">
                <option value="">- please select -</option>
                <cfloop query="qryUsers"> 
                  <option value="#UserID#">#FirstName#</option>
                </cfloop>
            </select>
        </form>
    </cfoutput>