<assign>

Assigns a value to a variable.

This variable must already have been declared using the <var> element, or in a var statement within a <script>. If the variable has not been defined, an error.semantic event is thrown.

Attributes

This section describes the attributes you can set for this element.

Name

Data type

Default

expr

CDATA

required

name

CDATA

required

expr

The expr attribute specifies the value assigned to the variable.

name

The name attribute specifies the name of the variable.

For example:

<assign name="variableName" expr="variableValue" />

Where:

  • variableName specifies any variable available in the current scope.
  • variableValue specifies any valid ECMAScript value.

In cases where the same variable name is used at different levels in the document, the name may be prefixed with a scope name to remove ambiguity.

Children

None.

Parents

Note: The <assign> element cannot be a child of <foreach> if <foreach> is itself a child of a <prompt> element.

Sample code

<vxml>
   <var name="x" expr="0"/>
   <form>
   <block>
      <clear/>
<assign name="x" expr="x+1"/>
      <log expr="'Infinite loop, execution number: ' + x"/>
      <prompt bargein="false"> 
         This infinite loop has run <value expr="x"/> times.
      </prompt>
      <clear/>
   </block>
   </form>
</vxml>

For a VoiceXML sample demonstrating the use of the <assign> element, see Blackjack.vxml located in the $NVP_HOME/appservice/applications/webapps/BlackJack directory. For information about samples, see Sample applications.