20.2. Referring to the
Value of a Variable in WML
To
refer to the value of a variable in WML, use the form $(variable
name). Whenever a WAP browser comes across a term of such form,
it will substitute the term with the stored value of the variable.
The
WML example below demonstrates how to refer to the value of a
variable in a card:
(varEg1.wml)
<?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="WML Variable"> <onevent
type="onenterforward"> <refresh> <setvar
name="var1" value="variable
1"/> </refresh> </onevent> <p> What's
your name? <input
name="name" maxlength="16"/><br/>
Which
part of our WML tutorial do you like? <select
name="tutorial_part"> <option
value="Part 1">Part 1</option> <option
value="Part 2">Part 2</option> <option
value="Part 3">Part
3</option> </select><br/><br/>
<a
href="#card2">Next Card</a> </p> </card>
<card
id="card2" title="WML Variable"> <p> Your
name is $(name).<br/><br/> You
like $(tutorial_part) of our WML tutorial.<br/><br/> The
value of var1 is <i>$(var1)</i>. </p> </card> </wml>
The
screenshots below show what you will see if you open the above WML
document in some mobile phone browsers:

 Sony
Ericsson T610
|

 Sony
Ericsson T68i
|

 Nokia
Mobile Browser 4.0
|
Type
Jack in the input field and then select the Part 2
option of the selection list. The values Jack and Part 2
are assigned to the variables name
and tutorial_part
respectively.

 Sony
Ericsson T610
|

 Sony
Ericsson T68i
|

 Nokia
Mobile Browser 4.0
|
After
selecting the "Next Card" anchor link, the mobile phone
browser prints out the values of variables name,
tutorial_part and var1
on the screen. You should see something similar to the following
screenshots:

 Sony
Ericsson T610
|


 Sony
Ericsson T68i
|

 Nokia
Mobile Browser 4.0
|
Feedback Form ( ExpandCollapse)
|