Page 123 - DCAP512_WAP_AND_WML
P. 123
Unit 9: Working with user Input
Notes
Table 9.1: Example Name Value Pair
Variable Name Variable Value
MyAge 31
A sample variable table is shown in Table 9.1. If variable data is not drawn from an earlier card
or a database, the initial value must be set. This can be done within a card using either
onenterforward or ontimer.
As we may recall, onenterforward effectively creates a card that is never seen by the user but can
be used by the browser. The ontimer binding sets the variable after a (very) brief pause.
Variable escaping is typically used within URLs (also called URL escaping) to replace particular
characters with ones that have a lower chance of misinterpretation or incorrect translation.
!
Caution Typically “safe” characters are ASCII letters, digits, and some punctuation (%)
marks.
Variables
It can be used in content.
It can be used in some attribute values.
It cannot be used for element or attribute names.
It can be used to store captured user inputs.
Variable value is set using <setvar> or control name attribute.
<setvar name =”first name” value=”Adam”/>
<input name =”firstname”/>
Anytime a single dollar sign is used in our text, it is seen as a variable reference. In order to
avoid this usage, we use two-dollar signs ($$) when referring to the currency. We can also use
the character reference form (&36), but again, it must be added.
Parentheses can be omitted if there is white space (<space> or <enter>) following a variable. Thus,
$time does not need them, but $date does. For consistency, it may be best to always use them.
Notes When a user switches from card to card in a deck, we need to store data in variables.
WML variables are case sensitive.
Specify a Variable with the Setvar Command
When someone executes a task (like go, prev, and refresh), the setvar element can be used to set
a variable with a specified value.
The following example will create a variable named i with a value of 500:
<setvar name=”i” value=”500"/>
The name and value attributes are required.
LOVELY PROFESSIONAL UNIVERSITY 117