Page 166 - DCAP512_WAP_AND_WML
P. 166
WAP & WML
Notes 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.
Self Assessment
Fill in the blanks:
14. …………………… displays a message, waits for an answer, and returns a Boolean value
depending on the selected answer.
15. …………………… separates a string into elements, and then returns a specified element.
160 LOVELY PROFESSIONAL UNIVERSITY