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


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