16.2. Displaying Confirmation Messages on the Screen of Wireless Devices: confirm() Function

The confirm() function of the Dialogs standard library is used to display a confirmation message on the screen of a wireless device. Below is the syntax of confirm():


Dialogs.confirm(message, ok, cancel);


message is the message to be displayed. If the user selects the option labeled with ok, the confirm() function returns the Boolean value true; if the user selects the option labeled with cancel, it returns the Boolean value false; if any error occurs, it returns invalid.

Below shows a WML/WMLScript example that illustrates the usage of confirm():


(confirmEg1.wml)

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd">

<wml>
  <card id="cell_phone_card" title="Buy Cell Phone">
    <p>
      Which cell phone do you want to buy?<br/>
      <select name="cell_phone_model">
        <option value="a">Model A</option>
        <option value="b">Model B</option>
        <option value="c">Model C</option>
      </select><br/><br/>

      <a href="confirmEg1.wmls#confirmBuy()">Continue</a>
    </p>
  </card>
</wml>


(confirmEg1.wmls)

extern function confirmBuy()
{
  var cell_phone = WMLBrowser.getVar("cell_phone_model");
  var message = "The price of the cell phone you have chosen is $";
  if ("a"==cell_phone)
    message += "200";
  else if ("b"==cell_phone)
    message += "300";
  else if ("c"==cell_phone)
    message += "250";
  message += ". Do you want to proceed to checkout now?";

  var toCheckout = Dialogs.confirm(message, "Yes", "No");
  if (true==toCheckout)
    WMLBrowser.go("checkout.wml");
}


Open the WML document of the example in a mobile phone browser:






Sony Ericsson T68i


Nokia Mobile Browser 4.0


If you choose any of the cell phone models and click the "Continue" link, the mobile phone browser will display a confirmation message that is generated by the confirm() function:






Sony Ericsson T68i


Nokia Mobile Browser 4.0


If you press the "Yes" button of the Sony Ericsson T68i emulator or the "Yes" softkey of the Nokia Mobile Browser, the mobile phone browser will load the WML file checkout.wml.


Previous Page Page 38 of 71 Next Page


Feedback Form (ExpandCollapse)

What do you think about this web page?






(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.

A button for going back to the top of this page