WML - Events
Event in ordinary language can be defined as something happens. In programming event is identical in meaning, but with one major difference. When something happens in a computer system, the system itself has to (1) detect that something has happened and (2) know what to do about it.
WML language also supports events and you can specify an action to be taken whenever an event occurs. This action could be in terms of WMLScript or simply in terms of WML.
WML supports following four event types:
onenterbackward: This event occurs when the user hits a card by normal backward navigational means. That is, user presses the Back key on a later card and arrives back at this card in the history stack.
onenterforward: This event occurs when the user hits a card by normal forward navigational means.
onpick: This is more like an attribute but it is being used like an event. This event occurs when an item of a selection list is selected or deselected.
ontimer: This event is used to trigger an event after a given time period.
These event names are case sensitive and they must be lowercase.
WML <onevent> Element:
The <onevent>...</onevent> tags are used to create event handlers. Its usage takes the following form:
A task to be performed.
You can use either go, prev or refresh task inside <onevent>...</onevent> tags against an event.
The <onevent> element supports the following attributes:
| Defines a type of event occured.|
|class||class data||Sets a class name for the element.|
|id||element ID||A unique ID for the element.|
Following is the example showing usage of <onevent> element. In this example whenever you try to go back from second card to first card then onenterbackward occurs which moves you to card number three. Copy and past this program and try to play with it.
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
<card id="card1" title="Card 1">
Go to card 2
<card id="card2" title="Card 2">
<card id="card3" title="Card 3">