Solved

pass a list to coldfusion cfselect

Posted on 2010-11-19
13
768 Views
Last Modified: 2012-05-10
Hi,
I have a drop down menu and wants to select the values according the list len and values. code is as under:

<cfset itemlist = 'joe,bob,harry,mary,Ann'/>
<cfform>
<cfselect name="hello" multiple="yes">
<cfloop list="#ListLen(itemlist)#" index="x" delimiters=",">
<option value="joe" <cfif #x# EQ "joe"> selected</cfif>>joe</option>
<option value="bob" <cfif #x# EQ "bob"> selected</cfif>>bob</option>
<option value="harry" <cfif #x# EQ "harry"> selected</cfif>>harry</option>
<option value="mary" <cfif #x# EQ "mary"> selected</cfif>>mary</option>
<option value="Ann" <cfif #x# EQ "Ann"> selected</cfif>>Ann</option>
<option value="bobi" <cfif #x# EQ "bobi"> selected</cfif>>bobi</option>
</cfloop>
</cfselect>
</cfform>

Open in new window


any help and comments would be deeply appreciated..
0
Comment
Question by:s_hausen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
13 Comments
 
LVL 1

Expert Comment

by:medsoos
ID: 34177413
Here's something that might work - it's for select not cfselect but concept is similar.

<select multiple name="hello">
<CFLOOP INDEX="x" LIST="#itemlist#" delimiters=",">
<OPTION <CFIF ListFind( #itemlist# , #x# ) is not 0>SELECTED</CFIF> VALUE="#Itemlist#">#ItemList# </OPTION>
</CFLOOP>
</select>
0
 

Author Comment

by:s_hausen
ID: 34177454
hi medsoos,
I tried to use your code but it doesn't give the result i needed. its printing all the values and not even selecting the values.
0
 
LVL 1

Expert Comment

by:medsoos
ID: 34177487
Yes, I'm sorry, I put in wrong variable. I think this is better:

 <cfoutput>
<select multiple="multiple"  name="hello">
<CFLOOP INDEX="x" LIST="#itemlist#" delimiters=",">
<OPTION <CFIF ListFind( #itemlist# , #x# ) is not 0>SELECTED</CFIF> VALUE="#X#">#x# </OPTION>
</CFLOOP>
</select>       
</cfoutput>
0
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 

Author Comment

by:s_hausen
ID: 34177631
Ok, its giving me the list but not selecting the values which are in the list. any comments??
0
 
LVL 1

Expert Comment

by:medsoos
ID: 34177810
<cfset itemlist = 'x,bob,x,mary,Ann,x'/>
<cfset itemlist0 = 'joe,bob,harry,mary,Ann,bobi'/>
 <body>
 <table><tr><td width="100"></td><td>
 <cfoutput>
<select  multiple="multiple" style="max-height:25; width: 150px"   name="hello">
<CFLOOP INDEX="x" LIST="#itemlist0#" delimiters=",">
<OPTION <CFIF ListFind( #itemlist# , #x# ) is not 0>SELECTED</CFIF> VALUE="#X#">#x# </OPTION>
</CFLOOP>
</select>      
</cfoutput>
</td>
</tr>
</table>
0
 
LVL 1

Expert Comment

by:medsoos
ID: 34177812
Hi S Hausen,

This was assuming in your selected items that were returned that bob, mary and Ann were selected. Does this make sense?

hth.
0
 
LVL 1

Accepted Solution

by:
medsoos earned 250 total points
ID: 34177850
Here it is with CFSELECT

 
<cfset itemlist = 'x,bob,x,mary,Ann,x'/>
<cfset itemlist0 = 'joe,bob,harry,mary,Ann,bobi'/>
<table>
  <tr>
      <td width="100"></td>
      <td>
      <cfoutput>
        <cfform name="myform">
          <cfselect size="6"  multiple="yes" style="max-height:55; width: 150px"   name="hello">
              <CFLOOP INDEX="x" LIST="#itemlist0#" delimiters=",">
              <OPTION <CFIF ListFind( #itemlist# , #x# ) is not 0>SELECTED</CFIF> VALUE="#X#">#x# </OPTION>
              </CFLOOP>
          </cfselect>      
        </cfform>
      </cfoutput>
      </td>
  </tr>
</table>

0
 
LVL 52

Expert Comment

by:_agx_
ID: 34177924
>> its giving me the list but not selecting the values which are in the list. any comments

There's no way that could happen ;-) The code medsoos posted in comment 34177487 works perfectly. So you must be using slightly different code.  

Can you post it?
0
 

Author Comment

by:s_hausen
ID: 34178069
hi agx,
the id 34177810 works fine. thanks for helping me out guys. I do appreciate it..
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34178608
Anytime :)
0
 
LVL 52

Expert Comment

by:_agx_
ID: 34178620
Btw: I forgot to mention you can omit the #'s and loop delimiter. They aren't needed.  

ie
...
<CFLOOP INDEX="x" LIST="#itemlist0#">
    <OPTION VALUE="#X#" <CFIF ListFind( itemlist , x )>SELECTED</CFIF> >#x# </OPTION>
</CFLOOP>
...
0
 
LVL 1

Expert Comment

by:medsoos
ID: 34178749
Good, thanks  _agx_!
0
 

Author Comment

by:s_hausen
ID: 34180251
thanks again guys..have a good weekend...
0

Featured Post

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question