9. WMLScript Variables Vs WML Variables

Note that WMLScript variables and WML variables are not the same thing. WMLScript variables are those you see in the last few sections. They are declared using the var keyword and they can only be used inside WMLScript functions.

WML variables are those variables whose values can be set and read using the WML markup language alone. For example, we can use the WML tag <setvar> to set the value of a WML variable without involving WMLScript. Further details about WML variables can be found in the "WML Variables" section of our WML tutorial.

WMLScript provides two functions in its WMLBrowser standard library for mobile Internet application developers to manipulate WML variables. They are setVar() and getVar().


9.1. Using WMLScript to Set the Value of a WML Variable

WMLScript's setVar() function is used to set the value of a WML variable. It should be used in the following form:


WMLBrowser.setVar(variable_name, value);


variable_name is the name of the WML variable you want to assign a value to, and value is the value you want to assign to variable_name. WMLScript requires value to be legal XML CDATA.

The setVar() function returns:

Here is an example demonstrating how to use the setVar() function:


WMLBrowser.setVar("message", "Hello World. Welcome to our WMLScript tutorial.");


The above line of script assigns the value "Hello World. Welcome to our WMLScript tutorial." to the WML variable message.


9.2. Using WMLScript to Obtain the Value of a WML Variable

WMLScript's getVar() function helps you obtain the value of a WML variable. It is used in the following form:


WMLBrowser.getVar(variable_name);


variable_name is the name of a WML variable.

The getVar() function returns:

Here is an example demonstrating how to use the getVar() function:


var wmlscript_variable = WMLBrowser.getVar("message");


When the WMLScript interpreter encounters the above line of script, the value of the WML variable message is assigned to the WMLScript variable wmlscript_variable.


Previous Page Page 14 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