Event in ordinary language can be defined as something happened. 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.
The <onevent>...</onevent> tags are used to create event handlers. Its usage takes the following form:
<onevent type="event_type"> A task to be performed. </onevent>
You can use either go, prev or refresh task inside <onevent>...</onevent> tags against an event.
The <onevent> element supports the following attributes:
|type||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 paste this program and try to play with it.
<?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml12.dtd"> <wml> <onevent type="onenterbackward"> <go href="#card3"/> </onevent> <card id="card1" title="Card 1"> <p> <anchor> <go href="#card2"/> Go to card 2 </anchor> </p> </card> <card id="card2" title="Card 2"> <p> <anchor> <prev/> Going backwards </anchor> </p> </card> <card id="card3" title="Card 3"> <p> Hello World! </p> </card> </wml>