Solved

pass a list to coldfusion cfselect

Posted on 2010-11-19
13
749 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
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.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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