16. WMLScript Dialogs Standard Library
WMLScript's Dialogs standard library contains three functions -- alert(), confirm() and prompt(). They are used to display alert messages, confirmation messages and input boxes to users. They can help reduce the number of trips to the WAP server. For example, let's say we have a WMLScript function that is used to check whether a certain variable's value is in the range 1 to 100. If it is outside the range, we will give the user a message to ask him/her to enter again. The message is stored in a WML document.
function
checkRange(number)
{
if (number <
1)
WMLBrowser.go("alertTooSmall.wml");
else if
(number >
100)
WMLBrowser.go("alertTooLarge.wml");
else
WMLBrowser.go("success.wml");
}
In the above script, if number is not in the range 1 to 100, the WML browser has to download the WML file alertTooSmall.wml or alertTooLarge.wml from the WAP server, which involves a round-trip.
Now we rewrite the above script using the alert() function of the Dialogs standard library, like this:
function
checkRange(number)
{
if (number <
1)
Dialogs.alert("Number too small. Please enter
again.");
else if (number >
100)
Dialogs.alert("Number too large. Please enter
again.");
else
WMLBrowser.go("success.wml");
}
The script instructs the WML browser to generate an alert message if number is out of range, which means the WML browser does not need to download the WML file alertTooSmall.wml or alertTooLarge.wml from the WAP server any more. Hence, a round-trip to the WAP server is saved and the WML browser will give a quicker response.
You can learn how to use the three functions of the Dialogs standard library in the following sections.
Previous Page | Page 36 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