WMLScript Tutorial
WMLScript Tutorial
WMLScript Introduction
What you should already know
Before you continue you should have a basic understanding of the following:
• HTML
• JavaScript
• WML.
What is WML?
• WML stands for Wireless Markup Language. It is a mark-up language inherited from HTML, but
WML is based on XML, so it is much stricter than HTML.
• WML is used to create pages that can be displayed in a WAP browser.
• Pages in WML are called DECKS. Decks are constructed as a set of CARDS.
What is WMLScript?
• WMLScript is the scripting language used in WML pages
• WMLScript is a light version of the JavaScript language
• WML scripts are not embedded into WML pages
• WML pages contains references to script URLs
• WMLScript is compiled into byte code on the server before it is sent to the WAP browser
• WMLScript is a part of the WAP specification
• What is WMLScript used for?
• WMLScript is used to validate user input
• WMLScript is used to generate message boxes, and to view errors and confirmations faster
• WMLScript is used to access facilities of the user agent
WMLScript How to
• How to call a WMLScript from a WML page
• WMLScripts are not embedded in WML pages.
• A WML page only contains references to script URLs.
In the example below, if you select the go label, the external script will direct you to
http://www.w3schools.com/wap.wml:<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="no1" title="Go to URL">
<do type="options" label="Go">
<go href="check.wmls#go_url('W3Schools')"/>
</do>
</card>
</wml>
The red line above contains a reference to a WMLScript. The script is in a file called check.wmls, and the
name of the function is go_url.
1
if (url=="W3Schools")
{
WMLBrowser.go("http://www.w3schools.com/wap.wml")
}
}
Note that the function is using the extern keyword. When using this keyword the function can be called by
other functions or WML events outside the .wmls file. To keep a function private, drop the extern keyword.
2
characterSet() Returns the character-set supported by the WMLScript
interpreter
exit() Exits a WMLScript and returns a message to the caller of
the script
float() Returns a Boolean value that indicates whether floating-
point numbers are supported
isFloat() Returns a Boolean value that indicates whether a value can
be converted into a floating-point number by the
parseFloat() function
isInt() Returns a Boolean value that indicates whether a value can
be converted into an integer by the parseInt() function
max(x,y) Returns the number with the highest value of x and y
maxInt() Returns the maximum possible integer value
min(x,y) Returns the number with the lowest value of x and y
minInt() Returns the minimum possible integer value
parseFloat() Returns a floating-point value defined by a string
parseInt() Returns an integer defined by a string
random(x) Returns a random integer between 0 and x
seed() Initializes the random number generator with a number,
and returns an empty string
Note: We think that the Lang library has a misleading name (should be named Math library or something like
that). However, it is called the Lang library because it contains functions that are closely related to the core
of the WMLScript engine.
3
length() Returns the length of a string
removeAt() Divides a string into elements and removes a specified
element
replace() Replaces a part of a string with a new string
replaceAt() Divides a string into elements and replaces a specified
element
squeeze() Reduces all multiple spaces to single spaces in a string
subString() Returns a specified part of a string
toString() Converts a value to a string
trim() Returns a string without leading and trailing spaces
4
The WMLBrowser library contains functions that can be used to access browser variables.
Note: The WML specification states that calls to library functions that are not supported by the browser
should return invalid. Because of this, all the above functions should be tested against their return value,
and proper action should be taken in case a function returns invalid.
Source: http://w3schools.com/wmlscript/default.asp
By: x2d4