– Common Function Library Project

ThisOrThat(thisValue[, defaultValue])

Last updated April 29, 2003


Shawn Seley

Version: 1 | Requires: CF5 | Library: StrLib

A shorthand way of specifying a default value to be returned if the primary value is empty (or contains only spaces). Handy for a variety of if-then uses.

Return Values:
Returns a string.


<cfset form.username1 = "Mickey Mouse">
<cfset form.username2 = "">
<cfset sql_aggregated_hours1 = 10>
<cfset sql_aggregated_hours2 = "">

Entered username 1:<br>
#ThisOrThat(form.username1, "(unknown user)")#<br>
Entered username 2:<br>
#ThisOrThat(form.username2, "(unknown user)")#<br>
SQL aggregated hours 1:<br>
#ThisOrThat(sql_aggregated_hours1, "0")#<br>
SQL aggregated hours 2:<br>
#ThisOrThat(sql_aggregated_hours2, "0")#<br>

A fault-tolerant "Go back" link (only relies on Javascript if a security precaution has prevented the return of the HTTP_REFERER):<br>
<a href="<cfoutput>#ThisOrThat(cgi.HTTP_REFERER, "javascript: history.go(-1)")#</cfoutput>">Go back</a>


Name Description Required
thisValue Value to check. Yes
defaultValue Value to use if thisValue is empty. Defaults to a non-breaking space. No

Full UDF Source:

 * Returns default value if primary value is empty.
 * Based on ValueOrSpace by David Grant (
 * @param thisValue      Value to check. (Required)
 * @param defaultValue      Value to use if thisValue is empty. Defaults to a non-breaking space. (Optional)
 * @return Returns a string. 
 * @author Shawn Seley ( 
 * @version 1, April 29, 2003 
function ThisOrThat(thisValue) {
    var defaultValue = "&nbsp;";
    if(arrayLen(arguments) gte 2) defaultValue = arguments[2];
    if (Len(Trim(thisValue)) LT 1) return defaultValue;
    return thisValue;


Latest Additions

Raymond Camden added
November 04, 2017

Leigh added
May 11, 2016

Raymond Camden added
May 10, 2016

Kevin Cotton added
May 05, 2016

Raymond Camden added
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson