| By Charlie Arehart | Article Rating: |
|
| September 17, 2003 12:00 AM EDT | Reads: |
8,691 |
If you have to test a condition against many values in a CFIF, you may be tempted to write out a very long condition, such as:
CFIF FORM.STATE IS "MA" OR FORM.STATE IS "VT" FORM.STATE IS "AK" ...
This quickly becomes unwieldy. There is an alternative approach. Simply use the LISTFIND (or LISTFINDNOCASE) function instead, as in:
CFIF LISTFIND("MA,VT,AK",FORM.STATE)
Note that the list of values is specified first, then the value to search for in the list. Also, the LISTFIND function presumes you are using commas to separate list values, but if you need to test strings that contain commas, you can specify an alternate delimiter as the 3rd argument in the function.
Finally, be careful about the case (upper/lower) of both comparison strings. If the value of FORM.STATE were "ma", the condition would not be true. To cause the condition to ignore case, use LISTFINDNOCASE instead.
Charlie Arehart Education Director, Fig Leaf Software
Published September 17, 2003 Reads 8,691
Copyright © 2003 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Charlie Arehart
A veteran ColdFusion developer since 1997, Charlie Arehart is a long-time contributor to the community and a recognized Adobe Community Expert. He's a certified Advanced CF Developer and Instructor for CF 4/5/6/7 and served as tech editor of CFDJ until 2003. Now an independent contractor (carehart.org) living in Alpharetta, GA, Charlie provides high-level troubleshooting/tuning assistance and training/mentoring for CF teams. He helps run the Online ColdFusion Meetup (coldfusionmeetup.com, an online CF user group), is a contributor to the CF8 WACK books by Ben Forta, and is frequently invited to speak at developer conferences and user groups worldwide.
- Validating Input with Regular Expressions
- Getting Focus()ed and a Quick JavaScript Lesson
- Setting Up Your Development Server with ColdFusion 5, MX, and BlueDragon
- Toward Better Error Handling
- Monitoring Your ColdFusion Environment With the Free Log Parser Toolkit
- New Possibilities for Session/Client Variable Handling in CFMX
- Testing Existence in Arrays
- Making the Case for CFML on J2EE
- Exploring Amazon Web Services with ColdFusion MX
- Getting Focused - and a Quick JavaScript Lesson
- CFML on J2EE: Easy as 1-2-3
- Getting into HomeSite+



























