16.1. Displaying Messages on the Screen of Wireless Devices: alert() Function

Preferences - Do not show ads

The alert() function of the Dialogs standard library is used to display a message on the screen of a wireless device. The WML browser goes back to the original card when the user confirms he/she has read it. Its syntax is like this:


message is the message to be displayed. The alert() function returns an empty string if everything works fine. It returns an invalid value if errors occur.

The following WML/WMLScript example illustrates how to use the alert() function:


<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd">

  <card id="card1" title="alert() Example">
      Enter a number between 1-100:<br/>
      <input name="number"/><br/><br/>
      <a href="alertEg1.wmls#checkRange($(number))">Continue</a>

  <card id="card2" title="alert() Example">
      The number you entered is $(number).


extern 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.");

The following screenshots show what you will see if you open the WML document of the above example in some mobile phone browsers:

Sony Ericsson T68i

Nokia Mobile Browser 4.0

If you enter 999 in the input field and click the "Continue" anchor link, a warning message is given informing you that the number is too large:

Sony Ericsson T68i

Nokia Mobile Browser 4.0

Click the "Yes" button of the Sony Ericsson T68i emulator or the "OK" softkey of the Nokia Mobile Browser 4.0 to go back to the original card:

Sony Ericsson T68i

Nokia Mobile Browser 4.0

Previous Page Page 37 of 71 Next Page

Contents at a Glance (Click Here for Full Table of Contents)
Print this Web Page | | Back to Top

Feedback Form (Expand)

What do you think about this web page?

WMLScript Tutorial Table of Contents WMLScript Tutorial Contents at a Glance Preferences - Change Color Scheme Preferences - Do Not Show Ads Previous Page Next Page