Solved

pass a list to coldfusion cfselect

Posted on 2010-11-19
13
744 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
<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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Accepted Solution

by:
medsoos earned 250 total points
Comment Utility
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_
Comment Utility
>> 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
Comment Utility
hi agx,
the id 34177810 works fine. thanks for helping me out guys. I do appreciate it..
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
Anytime :)
0
 
LVL 52

Expert Comment

by:_agx_
Comment Utility
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
Comment Utility
Good, thanks  _agx_!
0
 

Author Comment

by:s_hausen
Comment Utility
thanks again guys..have a good weekend...
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
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 …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

11 Experts available now in Live!

Get 1:1 Help Now