Solved

pass a list to coldfusion cfselect

Posted on 2010-11-19
13
745 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
  • 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
 

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now