ToggleValue(variable, value1, value2)
Last updated July 3, 2002
Version: 1 | Requires: ColdFusion 5 | 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 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:
<cfscript>
/**
* 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];
}
</cfscript>
Search CFLib.org
Latest Additions
Dave Anderson added
iniToStruct
20 day(s) ago
Dave Anderson added
deDupeArray
20 day(s) ago
Richard added
dice
22 day(s) ago
Isaac Dealey added
getRelative
a while ago
Top Rated
backupDatabase
Rated 5.0, 22 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)
highlightAndCrop
Rated 5.0, 4 time(s)