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():
<?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>
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:
|
|
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:
|
|
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 |
- 1. WMLScript Introduction
- 2. Hello World WMLScript Example
- 3. Compiling WMLScript Code
- 4. WMLScript Language Rules
- 5. Defining WMLScript Functions
- 6. Calling WMLScript Functions
- 7. WMLScript Variables
- 8. WMLScript Data Types
- 9. WMLScript Variables Vs WML Variables
- 10. Passing Arguments to Functions By Value and By Reference
- 11. WMLScript Operators
- 12. WMLScript Conditional Statements
- 13. WMLScript Looping Statements
- 14. WMLScript Standard Libraries Overview
- 15. WMLScript WMLBrowser Standard Library
- 16. WMLScript Dialogs Standard Library
- 17. WMLScript String Standard Library
- 18. WMLScript Float Standard Library
- 19. WMLScript Lang Standard Library
- 20. WMLScript URL Standard Library
- 21. WMLScript Example: Validating Form Data