# <assign>

Description

The `<assign>` element assigns a value to a variable.

In standards compliance mode, attempting to `<assign>` a value to a variable which has not been previously declared (with `<var>`) will result in an `error.semantic` event being thrown. If the `com.voicegenie.STRICTCONFORMANCE` property is set to `FALSE`, the variable can be assigned without being declared previously.

Syntax

    <assign
        name="string"
        expr="ECMAScript_Expression"/>

Attributes

Attribute | Description
name | The name of the variable being assigned to. Required.
expr | An ECMAScript expression to be evaluated and used as the value assigned to the variable. Required.

Attribute Notes

- An `error.semantic` event is thrown if the application attempts to `<assign>` a value to a session variable (i.e. if `name` refers to a session variable).

Parents

<block>, <catch>, <error>, <filled>, <foreach>, <help>, <if>, <noinput>, <nomatch>

Children

None.

extensions

None.

Limitations/Restrictions

- `<assign>` cannot be used as a child of `<foreach>` when `<foreach>` is a child of `<prompt>`.

Example

    <?xml version="1.0"?>
    <vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
      <var name="var1" expr="'first'"/>
      <form>
        <block>
          The initial value is <value expr="var1"/>.
          <assign name="var1" expr="'second'"/>
          The new value is <value expr="var1"/>.
        </block>
      </form>
    </vxml>