– 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;
blog comments powered by Disqus


Latest Additions

Kevin Cotton added
May 5, 2016

Raymond Camden added
April 25, 2016

Chris Wigginton added
January 18, 2016

Gary Stanton added
November 19, 2015

Sebastiaan Naafs - van Dijk added
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson