Last reviewed: 3/23/2024 12:20:46 PM
In this article
<if>
An <if> element is used for simple conditional logic.
Syntax
<if cond="expression">
Attributes
cond
An expression to evaluate in conjunction with the test of the form item variable.
Children
<assign>, <audio>, <clear>, <disconnect>, <else>, <elseif>, <enumerate>, <exit>, <goto>, <if>, <log>, <prompt>, <reprompt>, <return>, <script>, <submit>, <throw>, <value>, and <var>.
Parents
<block>, <catch>, <error>, <filled>, <help>, <if>, <noinput>, <nomatch>, and <prompt>,
Variables
none
Example
The following example illustrates if condition logic.
<if cond="total > 1000">
<prompt>This is way too much to spend.</prompt>
<throw event="com.xyzcorp.acct.toomuchspent"/>
</if>
<if cond="amount < 29.95">
<assign name="x" expr="amount"/>
<else/>
<assign name="x" expr="29.95"/>
</if>
<if cond="flavor == 'vanilla'">
<assign name="flavor_code" expr="'v'"/>
<elseif cond="flavor == 'chocolate'"/>
<assign name="flavor_code" expr="'h'"/>
<elseif cond="flavor == 'strawberry'"/>
<assign name="flavor_code" expr="'b'"/>
<else/>
<assign name="flavor_code" expr="'?'"/>
</if>
Version Information
Supported in: VoiceXML 1.0, VoiceXML 2.0, and VoiceXML 2.1.