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:
<?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>
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:
|
|
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:
|
|
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:
|
|
Previous Page | Page 37 of 71 | Next Page |
- 1. WMLScript Introduction
- 2. Hello World WMLScript Example
- 3. Compiling WMLScript Code
- 4. WMLScript Language Rules
- 5. Defining WMLScript Functions
- 6. Calling WMLScript Functions
- 7. WMLScript Variables
- 8. WMLScript Data Types
- 9. WMLScript Variables Vs WML Variables
- 10. Passing Arguments to Functions By Value and By Reference
- 11. WMLScript Operators
- 12. WMLScript Conditional Statements
- 13. WMLScript Looping Statements
- 14. WMLScript Standard Libraries Overview
- 15. WMLScript WMLBrowser Standard Library
- 16. WMLScript Dialogs Standard Library
- 17. WMLScript String Standard Library
- 18. WMLScript Float Standard Library
- 19. WMLScript Lang Standard Library
- 20. WMLScript URL Standard Library
- 21. WMLScript Example: Validating Form Data