var
var element
Declares a variable.
Syntax
<var
expr = "ECMAScript_Expression"
name = "string"
/>
Attributes
expr |
An ECMAScript expression to evaluate. If this value is a string, you must enclose it in single quotation marks. If you do not specify an initial value for the variable, it retains its current value, if it has already been declared. |
name |
Required. The variable's name. |
Parents
block, catch, error, filled, foreach, form, help, if, menu, noinput, nomatch, prompt, vxml
Children
None.
Remarks
The var element declares a variable within the scope defined by its container. A variable is accessible to all children of that container.
The var element is also used to declare param to be passed to a subdialog.
The name attribute can contain letters, digits, underscores "_", and dollar signs "$", but the first character must be a letter or a dollar sign.
Examples
The following example asks the user to say the name of an element. The Platform assigns the user's utterance to a form item variable named element. The filled handler for the dialog assigns the form item variable to another variable with the same name declared at document scope. The value of the variable is then assigned the value of the variable name desired_element.
<?xml version="1.0"?>
<vxml version="2.1"
xmlns="http://www.w3.org/2001/vxml">
<var name="element" />
<var name="desired_element" expr="'wine'"/>
<link event="help">
<grammar mode="voice"
root="root_rule"
tag-format="semantics/1.0"
type="application/srgs+xml"
version="1.0"
xml:lang="en-US">
<rule id="root_rule" scope="public">
<one-of>
<item>
help
</item>
</one-of>
</rule>
</grammar>
</link>
<form id="get_element">
<field name="element">
<prompt>
Say an element
</prompt>
<grammar mode="voice"
root="root_rule"
tag-format="semantics/1.0"
type="application/srgs+xml"
version="1.0"
xml:lang="en-US">
<rule id="root_rule" scope="public">
<one-of>
<item>
<one-of>
<item>
water
</item>
</one-of>
<tag>out.element = "water";</tag>
</item>
<item>
<one-of>
<item>
earth
</item>
</one-of>
<tag>out.element = "earth";</tag>
</item>
<item>
<one-of>
<item>
fire
</item>
</one-of>
<tag>out.element = "fire";</tag>
</item>
<item>
<one-of>
<item>
air
</item>
</one-of>
<tag>out.element = "air";</tag>
</item>
</one-of>
</rule>
</grammar>
<noinput>
I'm sorry. I didn't hear you.
<reprompt/>
</noinput>
<nomatch>
I'm sorry. I didn't get that.
<reprompt/>
</nomatch>
<help>
You're choosing an element. Say earth, fire, air, or water.
</help>
<filled>
<assign name="document.element" expr="element"/>
<goto next="#alchemy"/>
</filled>
</field>
</form>
<form id="alchemy">
<block>
Converting <value expr="element"/> to <value expr="desired_element"/>
<assign name="element" expr="desired_element"/>
<log>selected element converted to <value expr="element"/></log>
<exit />
</block>
</form>
</vxml>