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:
<?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>
Code for ConditionalExample.wml.
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");
};
Code for ConditionalExample.wmls.