WML - Events

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.

WML <onevent> Element:

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.

You can use either go, prev or refresh task inside <onevent>...</onevent> tags against an event.

The <onevent> element supports the following attributes:

  • onenterbackward
  • onenterforward
  • onpick
  • ontimer
Defines a type of event occured.
classclass dataSets a class name for the element.
idelement IDA 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"?>

<onevent type="onenterbackward">
  <go href="#card3"/>

<card id="card1" title="Card 1">
     <go href="#card2"/>
     Go to card 2
<card id="card2" title="Card 2">
      Going backwards
<card id="card3" title="Card 3">
Hello World!