November 28, 2014
Hot Topics:

Learning WML - Variables and Scripting

  • July 29, 2002
  • By Steve Schafer
  • Send Email »
  • More Articles »

This series of articles describes how to provide Web content to mobile devices through WML (Wireless Markup Language). This article covers variables and beginning scripting with WMLScript. Future articles will cover more advanced scripting and how to integrate other technologies such as PHP to make your pages more flexible.

Note: These articles cover WML and WMLScript version 1.1, which are supported by the majority of mobile devices in use today. The articles assume a working knowledge of HTML and general Web technologies, and further assume that you have read the previous article(s) in this series.

Understanding Variables

WML supports variables that can hold transitional data between cards, provide custom output tailored to individual users, and more.

Variables are special holding places for values. They can hold numeric or alpha values and their values can be changed by code at the programmer's whim. However, it is usually good practice to dedicate variables to particular purposes, and hence, to particular types of data.

Variables in WML consist of words, enclosed in parentheses, prefixed with a dollar sign ($). For example:


Note: Because the dollar sign ($) is used to signify a variable, it is a reserved character in WML. If you want an actual dollar sign to appear anywhere in your card(s), use a double dollar sign instead ("$$").

Variable names must start with a letter or underscore. Subsequent characters can be alpha, numeric, or underscores. Variables are case sensitive; "phone_number" is different from "Phone_Number."

Wherever a variable is referenced, WML will substitute the value of the variable where the variable name appears. For example, the following code:

     Hello $(name)!

would produce the following result, if "David" was stored in the variable $(name):

  Hello David!

Note: WML reserves the ampersand symbol (&) for entities. To use this symbol in your deck, you must substitute the corresponding entity "&amp;".

Setting Variables

Variables can be set by the following elements:


Each of these elements is discussed in more detail below. Note that some of these elements were introduced in previous articles, and their parameters and such will not be detailed here.

The <input> Element

The <input> element is straightforward; it accepts user input and stores it in the variable specified. For example, the following code would accept input for a phone number and store it in the variable $(phone_number). The number is then displayed on the second card.

<?xml version="1.0"?>


<card id="card1" title="Enter Number">
<do type="accept" label="Next">
     <go href="#card2" />
   What is your phone number?
   <input name="phone_number" 
             type="text" format="(NNN) NNN-NNNN" />

<card id="card2" title="Display Number">
     Your number is:<br/>


Note: The <input> element accepts a "value" attribute that can set a default value for the input. However, if the variable specified has already been assigned a value, the "value" attribute is ignored.

Page 1 of 3

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel