assign element
Last Updated: 02-17-2005
VoiceXML 2.0
Assigns a value to a variable.

Syntax

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

Attributes
expr
Required. The value to assign to the variable.
name
Required. The name of the variable.

Parents
None.

Children
None.

Remarks
Before using the assign element on a variable, you must first declare it using the var element.
If this value is a string, you must enclose it in single quotation marks.
Examples

The following example declares four variables at document scope, uses the assign element to calculate the cost of a product, and plays the information back to the user in a sentence.

<?xml version="1.0"?>
<vxml version="2.1"
 xmlns="http://www.w3.org/2001/vxml">
   <!--document-scoped variables -->
   <var name="product" expr="'windbreaker'"/>
   <var name="retail_price" expr="135"/> 
   <var name="discount" expr=".35"/> 
   <var name="cost"/>  

   <form id="check_price">
      <block>  
         <assign name="cost" expr="retail_price*discount"/>  
         <prompt>With a <value expr="discount*100"/> percent discount, 
         the cost of the <value expr="product"/> is <value expr="cost"/></prompt>  
      </block> 
   </form>
</vxml>


[24]7 Inc.| Terms of Service| Privacy Policy| General Disclaimers