W3C home > Mailing lists > Public > www-forms@w3.org > September 2003

RE: Defining "onClick"-Events in XForms Controls

From: Mark Birbeck <Mark.Birbeck@x-port.net>
Date: Tue, 30 Sep 2003 12:05:45 +0100
Message-ID: <E3ED00A7C285EE408679DE2A26D1C7810148F780@S007.x-port.net>
To: 'Roman Huditsch ' <roman.huditsch@hico.com>
Cc: "'www-forms@w3.org '" <www-forms@w3.org>

Hi Roman,

> How would I define a "onClick"-Event in an XForms control that calls a
> Javascript function?
> Would it look like
> <xforms:trigger html:onClick="javascript:test();">...


Before we look at how it's done, it's worth just pointing out how the
approach you suggest illustrates well the limitations of the old-style
(HTML) event definition versus XML Events, as used in XForms.

As you can see in your suggested code you could only ever have one handler
at a time for the onClick event on your element, if we use an attribute to
specify it. In XForms you can have as many handlers as you like, since they
can be expressed externally to the element that the event will originate

Also note that the problem with the name "onClick" is that it is device
specific. It implies something like a mouse, and in turn, that the
xf:trigger is a button. But in a voice system (for example) an xf:trigger
will not be a gray button, and activating the xf:trigger will not involve a

In DOM 2 Events the event name DOMActivate is used to indicate that the
element has been "activated" in some way. Obviously in a visual system this
is most likely to be with a mouse, but might not be.

So, if you wanted to show a message when a trigger is activated you could do

 <xforms:trigger id="tr">
  <xforms:message level="modal" ev:event="DOMActivate">
    Testing 1 2 3

And to execute your JavaScript routine, you could add this:

 <script for="tr" event="DOMActivate" language="JavaScript">
  alert('Add some code here');

As this sample stands, *both* the message and your inline JavaScript would
get executed, one after the other, but note that although DOM 2 Events
allows many handlers to be attached to the same event, there is no way to
specify what order they occur in.



Mark Birbeck
x-port.net Ltd.
Received on Tuesday, 30 September 2003 07:09:24 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:36:08 UTC