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.
Feedback Form ( ExpandCollapse)
|