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

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:


Dialogs.alert(message);


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:


(alertEg1.wml)

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

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

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


(alertEg1.wmls)

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.");
  else
    WMLBrowser.go("#card2");
}


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


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