You now know just about everything there is to know about actually using WML variables, but one thing you don’t yet know is how to put useful values into the variables in the first place!
Actually, there are three ways. The most common is through the use of
the various user interface elements, which are described in Chapter 4. Variables can also be set from WMLScript, as
explained in Chapter 19. The third way is with the
This element must be placed within a task element (described in Chapter 3). Its purpose is to represent an assignment to a WML variable. This assignment takes place when the task is executed.
name(required; variable string)
Specifies the name of the variable to be set
value(required; variable string)
Specifies the new value for the variable
For example, the element:
<setvar name="var" value="foo"/>
creates a variable called
var, containing the
foo. If a variable called
var already exists, this changes its value to the
Before executing one or more
elements within a task, the browser first expands all variables in
attributes. Note that this makes the order of the
<setvar> elements within a task unimportant.
To illustrate this behavior, imagine that the variable
x contains the value
three. Now suppose a
task contains these three
<setvar name="x" ...