3.49 script
Element type |
script |
Attributes |
charset | fetchhint | fetchtimeout | maxage (2.0) | maxstale (2.0) | src |
Parents |
block | catch | error | filled | form | help | if | menu | noinput | nomatch | vxml |
Children |
PCDATA |
Description |
Instructs the interpreter to execute the contents of this element or the external script it refers to using the ECMAScript interpreter that manages the other VoiceXML variables. |
DTD
<!ELEMENT script (#PCDATA) > <!ATTLIST script src %uri; #IMPLIED charset CDATA #IMPLIED %cache.attrs; >
Language model

Attributes
-
charset : CDATA
Indicates the character encoding of the external resource if the src attribute is used.
-
fetchhint : (prefetch | safe)
Indicates whether the interpreter may prefetch the destination document specified by this element's next attribute. A value of prefetch indicates the resource may be retrieved at the time the containing VoiceXML document is retrieved. A value of safe indicates that the resource specified by this element should not be prefetched, but should instead be retrieved at the time that the interpreter executes this element.
-
fetchtimeout : duration
The interval to wait for the content to be returned before throwing an error.badfetch event. If this attribute is not specified, the interpreter derives a value from the most locally scoped fetchtimeout property.
-
maxage : integer
Indicates the maximum allowable age of the fetched document in seconds. If the cached copy is older than the specified maxage, a new copy will be fetched when the interpreter executes this element. If this attribute is not specified, the interpreter derives a value from the most locally scoped maxage property. If no maxstale attribute is defined and it is impossible to fetch a new copy on the content the interpreter will throw an error.badfetch instead of using stale content.
-
maxstale : integer
Indicates that the interpreter may use stale content for this element as long as its age is no older than maxage plus the value of maxstale in seconds. If this attribute is not specified, the interpreter derives a value from the most locally scoped maxstale property.
-
src : uri
Indicates that the body of this script element is stored at the given URI.
Children
CDATA containing ECMAScript code.
Examples
Example 3-60 Various applications of the script element
<vxml version="2.0"> <var name="taxrate" expr=".0825"/> <!-- A simple script for computing the tax rate --> <script><![CDATA[ function computeTax(valInCents){ return taxrate * valInCents; } ]]></script> <!-- A JSP that returns the cartInfo variable in the form of ECMAScript assignments --> <script src="GetCartInfo.jsp"/> <form id="completesale"> <block> <prompt>Your subtotal is <value expr="cartInfo.subTotal"/>.</prompt> </block> <field name="expressmail" type="boolean"> <prompt>Would you like to ship this using express mail for an additional <say-as type="currency"> <value expr="computeShipping(cartInfo.weight)"/>? </say-as> </prompt> </field> <filled> <var name="total"/> <script><![CDATA[ total = cartInfo.subTotal + computeTax(cartInfo.subTotal) + expressmail?computeShipping(cartInfo.weight):0; ]]> </script> <prompt>Your total comes to <value expr="total"/>.</prompt> </filled> </form> </vxml>
Example 3-60 demonstrates how to use the script element to define inline ECMAScript processing as well as referencing ECMAScript stored externally - in this case generated from a JSP. You'll notice that the variables declared from VoiceXML (e.g. form field variables or variables declared using the var element) are accessible to the ECMAScript code.