Solved

pass a list to coldfusion cfselect

Posted on 2010-11-19
13
760 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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