<if>

The <if> element is used for conditional logic. It has optional <else> and <elseif> elements.

Attributes

cond An ECMAScript expression to evaluate.

Notes

None


Example

<?xml version="1.0"?>
<vxml version="2.0">
  <form>
    <field name="myprompt" type="digits">
      <prompt>
        Say the magic number between 1 and 9.
      </prompt>
      <filled>
        <!-- The "cond" attribute within an "if" tag -->
        <!-- should contain a boolean ECMAscript expression. -->
        <if cond="myprompt==5">
          <prompt>
            You guessed correctly!
          </prompt>
          <elseif cond="myprompt==4 || myprompt==6"/>
          <prompt>
            You're close. Try again.
          </prompt>
          <clear namelist="myprompt"/>
          <else/>
          <prompt>
            Try again.
          </prompt>
          <clear namelist="myprompt"/>
        </if>
      </filled>
    </field>
  </form>
</vxml>

The output of the above script would be:

Computer: Say the magic number between one and nine.
Human: Three.
Computer: Try again. Say the magic number between one and nine.
Human: Six.
Computer: You're close. Try again. Say the magic number between one and nine.
Human: Five.
Computer: You guessed correctly!



Child Tags

<audio>, <assign>, <clear>, <data>, <disconnect>, <else>, <elseif>, <enumerate>, <exit>, <foreach>, <goto>, <if>, <log>, <prompt>, <reprompt>, <return>, <script>, <submit>, <throw>, <value>, <var>



Parent Tags

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