User Guide
Chapter 2: ColdFusion Functions 515
SetVariable
The function sets the variable specified by name to value and returns the new value of
the variable.
See also DeleteClientVariable and GetClientVariablesList.
Syntax SetVariable(
name
,
value
)
name
Valid variable name.
value
String or number assigned to the variable.
Usage When setting client variables, it is required that the client variable exists prior to the
using of this function and the ClientManagement attribute of CFAPPLICATION tag has
been set to "Yes" for this template.
Examples <!--- This example shows SetVariable --->
<HTML>
<HEAD>
<TITLE>
SetVariable Example
</TITLE>
</HEAD>
<BODY BGCOLOR=silver>
<H3>SetVariable Example</H3>
<CFIF IsDefined("FORM.myVariable")>
<!--- strip out url, client., cgi., session., caller. --->
<!--- This example only lets you set form variables --->
<CFSET myName = ReplaceList(FORM.myVariable,
"url,client,cgi,session,caller", "FORM,FORM,FORM,FORM,FORM")>
<CFSET temp = SetVariable(myName, FORM.myValue)>
<CFSET varName = myName>
<CFSET varNameValue = Evaluate(myName)>
<CFOUTPUT>
<P>Your variable, #varName#
<P>The value of #varName# is #varNameValue#
</CFOUTPUT>
</CFIF>
...