WMLScript » Operators » Conditional

Syntax:
? : ;

The conditional operator is used to assign one of two possible values to an expression based upon the results from a boolean test applied to a specified operand.

The conditional operator is used in the following format:

expression = operand1 ? operand2 : operand3;

This operator behaves as follows:

  • A boolean (true or false) test is performed on operand1.
  • If the test proves true, the expression is assigned the value of operand2.
  • If the test proves false or invalid, the expression is assigned the value of operand3.

    Examples

    Code:
    <?xml version="1.0"?>
    <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
    "http://www.WAPforum.org/DTD/wml_1.1.xml">
    <wml>

    <card id="card1">
       <p>
       conditional example
       </p>
       <do type="accept">
          <go href="ConditionalExample.wmls#findconditional()" />
       </do>
    </card>

    <card id="card2">
    <p>
       expression = $(express)
    </p>
    </card>

    </wml>
    Explanation:

    Code for ConditionalExample.wml.

    Language(s): WML
    Code:
    extern function findconditional()
    {
       var oper1;
       var oper2 = "second operand";
       var oper3 = "third operand";
       var boo = Dialogs.prompt("true, false, or invalid", "");
       if(boo == "true") oper1 = true;
       if(boo == "false") oper1 = false;
       if(boo == "invalid") oper1 = invalid;
       var exp = oper1 ? oper2 : oper3;
       WMLBrowser.setVar("express", exp);
       WMLBrowser.go("ConditionalExample.wml#card2");
    };
    Explanation:

    Code for ConditionalExample.wmls.

    Language(s): WML

    See Also: