<assign>

Assigns a value to a variable.

Syntax

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

Description

Attribute Description
name

Name of variable. This variable must have already been declared.

expr

JavaScript expression that evaluates to the value assigned to this variable.

Tips:

 •  In JavaScript, + means both string concatenation and add. By default, values are treated as strings. If you want to add two numbers represented by string variables a and b in an <assign>, use:
      <assign name="x" expr="Number(a) + Number(b)"/>
 •  Multiply, divide, and subtract are not ambiguous in this way.
 •  If a JavaScript expression contains any of the characters "<", ">", or "&", that character must be replaced with the corresponding escape sequence "&lt;", "&gt;", or "&amp;". For more information, see JavaScript Quick Reference.

Usage

Parents Children
<bevocal:foreach>
<block>
<catch>
<error>
<filled>
<help>
<if>
<noinput>
<nomatch>

None

Exception

Exception Description

error.badfetch

If the name or expr attribute is missing.

See Also

 •  VoiceXML 2.0 Specification: <assign>
 •  JavaScript Quick Reference
 •  Related tag: <var>

Examples

 <?xml version="1.0" ?>
 <!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN"
  "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">
 
 <vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
   <form id="foo">
     <var name="a"/>
     <var name="b"/>
     <var name="result"/>
     <block>
       <assign name="a" expr="'Pine'"/>
       <assign name="b" expr="'Apple'"/>
       <assign name="result" expr="a + b"/>
     </block>
     <block>
       <prompt>
         This is the test for the assign tag.
         If you put <value expr="a"/> and <value expr="b"/> together,
         it would make <value expr="result"/>
       </prompt>
     </block>
   </form>
 </vxml>

[Show Frames]   [FIRST] [PREVIOUS] [NEXT]
BeVocal, Inc. Café Home | Developer Agreement | Privacy Policy | Site Map | Terms & Conditions
Part No. 520-0001-02 | © 1999-2007, BeVocal, Inc. All rights reserved | 1.877.33.VOCAL