ToggleValue(variable, value1, value2)
Last updated July 03, 2002
Version: 1 | Requires: CF5 | Library: UtilityLib
	Description: 
	Save yourself a couple lines of coding next time you need to toggle the value of a variable.
	Return Values: 
	Returns a string.
Example:
<cfset action = "On">
<cfset newValue = toggleValue(action,"On","Off")>
<cfoutput>Action = #action#, toggle is #toggleValue(action,"On","Off")#</cfoutput>
Parameters:
| Name | Description | Required | 
|---|---|---|
| variable | The variable that stores the value you will toggle. | Yes | 
| value1 | The first value of the toggle. | Yes | 
| value2 | The second value of the toggle. | Yes | 
Full UDF Source:
/**
 * Toggles a value (ie: "stop"/"start") between two options.
 * 
 * @param variable      The variable that stores the value you will toggle. (Required)
 * @param value1      The first value of the toggle. (Required)
 * @param value2      The second value of the toggle. (Required)
 * @return Returns a string. 
 * @author Nathan Dintenfass (nathan@changemedia.com) 
 * @version 1, July 3, 2002 
 */
function toggleValue(variable,value1,value2){
    //make a struct in which the value is the opposite of the key
    var toggler = structNew();
    toggler[value1] = value2;
    toggler[value2] = value1;
    //return whichever value is not the current value
    return toggler[variable];
}
Search CFLib.org
Latest Additions
									
									Raymond Camden added 
									QueryDeleteRows 
									November 04, 2017
								
								
									
									Leigh added 
									nullPad 
									May 11, 2016
								
								
									
									Raymond Camden added 
									stripHTML 
									May 10, 2016
								
								
									
									Kevin Cotton added 
									date2ExcelDate 
									May 05, 2016
								
								
									
									Raymond Camden added 
									CapFirst 
									April 25, 2016