I like using CF's "short circuit" logic (introduced in 4.5, I think?) like this:
<CFIF IsDefined("variable") AND Len(Variable)> #variable# </CFIF> Evaluation is sequential in the CFIF. This way, you only show the variable if it exists and is not empty. Something similar can be done with numbers: <CFIF IsDefined("variable") AND IsNumeric(Variable)> #variable# </CFIF> Or make sure the number is not zero: <CFIF IsDefined("variable") AND IsNumeric(Variable) AND Variable> #variable# </CFIF> Etc... Chris Lofback Sr. Web Developer TRX Integration 28051 US 19 N., Ste. C Clearwater, FL 33761 www.trxi.com -----Original Message----- From: Justin Scott [mailto:[EMAIL PROTECTED]] Sent: Monday, June 03, 2002 3:36 PM To: CF-Talk Subject: Re: if value exists, show it Hi Trey! > I simply want to test to see if a variable has a value (eg text has been > returned from a query) and if so, show it. There seem to be a few options -- > > <cfif isdefined(#variable#)> > #variable# > </cfif> As Raymond already pointed out, isDefined() takes a string as the input and returns a boolean that tells if the variable exists or not. This will return true even if the string is empty. There is no locking required specifically for isDefined(). > <cfif len(#variable#) GT 0> > #variable# > </cfif> This assumes the variable exists and will output its contents if it is not empty (sounds closest to what you want). This could be better written simply as.. <cfif len(variable)> > <cfif #variable# IS ""> > #variable# > </cfif> This will not do much, since you're displaying the string if it IS empty. If you changed the operator to IS NOT or NEQ it would act just like the len() does above. I would presonally prefer using len() in this case. -Justin Scott, Lead Developer Sceiron Internet Services, Inc. http://www.sceiron.com ______________________________________________________________________ Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists