Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
I am the chief technical officer at InVision App, Inc - a prototyping and collaboration platform for designers, built by designers. I also rock out in JavaScript and ColdFusion 24x7.
Meanwhile on Twitter
Loading latest tweet...
Ben Nadel at the jQuery Conference 2010 (Boston, MA) with:

Neat Trick With ValueList()

By Ben Nadel on
Tags: ColdFusion

This is just a quick little trick for outputting a list of items with proper spacing. You can use ColdFusion ValueList() using a delimiter that has both a comma AND a space in it: ", ". While this is not really a valid delimiter, which is defined as one character, the ValueList() method will still use both characters when creating the delimited list. Now, you have a nicely spaced list.

  • <cfquery name="qTags" datasource="...">
  • name
  • FROM
  • tag
  • name ASC
  • </cfquery>
  • <!--- Output nicely formatted tag list. --->
  • Tags: #ValueList(, ", " )#
Tweet This Provocative thoughts by @BenNadel - Neat Trick With ValueList() Thanks my man — you rock the party that rocks the body!

Looking For A New Job?

100% of job board revenue is donated to Kiva. Loans that change livesFind out more »

Reader Comments

I love CF's list functions. :)

Of course, for the other sort of lists, you can also do this:
<ul><li>#ValueList(, "</li><li>" )#</li></ul>

which has come in handy for me on a couple of occasions.

Reply to this Comment

I'm doing a zip code radius search which I do in another query before pulling my list of companies from my company table. The list of zip codes goes into my search query and are listed in order of distance from the source zip code. So I want the output of the second to be the same order as the value list...

Any ideas?

Reply to this Comment


Loop over your original list of zip codes and do a QofQ based on that zip against your result set.

Reply to this Comment


I'm not quite sure I follow what you mean; but as @Laurence pointed out, a query-of-queries can help you address values on a one-off basis.

Reply to this Comment

What would happen if you wanted to properly html-escape these values in order to prevent cross-site-scripting attacks, or even just display bugs?
(e.g. what if we're talking about algebra, and one of my tags is "a < b > c"? Do you just turn the rest of your website bold?)

Reply to this Comment

Jerry, if you're using Ben's example, you just run HtmlEditFormat (or similar) on the value produced by ValueList.

For my <li>-based example, it would probably be simplest to loop through manually and call HtmlEditFormat on each one (and if you're doing that, you might as well manually build the string instead of using ValueList).

Of course, it would be handy if the ValueList function had the ability to pass a callback function to allow you to process each item before appending it to the list, but unfortunately that's not possible (well, unless you were to write your own ValueList function to do it).

Reply to this Comment

Thanks! Exactly what I was looking for to do a comparison of two data sets and highlight duplicate results contained in the ValueList using a cfif.

Reply to this Comment

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.