SetVariable

Description

Sets a variable in the name parameter to the value of the value parameter. The SetVariable function is a dynamic evaluation function. Do not use untrusted code when using dynamic evaluation functions.

Returns

The new value of the variable.

Category

Dynamic evaluation functions

Function syntax

SetVariable(name, value)

See also

DEEvaluateIIf

Parameters

Parameter

Description

name

Variable name

value

A string, the name of a string, or a number

Usage

You can use direct assignment statements in place of this function to set values of dynamically named variables. To do so, put the dynamically named variable in quotation marks and number signs (#); for example:

<cfset "#DynamicVar2#" = "Test Value2">

Also, the following lines are equivalent:

<cfset "myVar#i#" = myVal>

SetVariable("myVar" & i, myVal)

For more information, see Using Expressions and Number Signs in the Developing ColdFusion Applications.

Example

<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>

 Adobe

쉽고 빠르게 지원 받기

신규 사용자이신가요?

Adobe MAX 2024

Adobe MAX
크리에이티비티 컨퍼런스

10월 14~16일 마이애미 비치 및 온라인

Adobe MAX

크리에이티비티 컨퍼런스

10월 14~16일 마이애미 비치 및 온라인

Adobe MAX 2024

Adobe MAX
크리에이티비티 컨퍼런스

10월 14~16일 마이애미 비치 및 온라인

Adobe MAX

크리에이티비티 컨퍼런스

10월 14~16일 마이애미 비치 및 온라인