Copyright © tutorialspoint.com

WML - Events

previous next


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:

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.
</onevent>

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

The <onevent> element supports the following attributes:

AttributeValueDescription
type
  • 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 past 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>

previous next

Copyright © tutorialspoint.com