- From: Mark Birbeck <Mark.Birbeck@x-port.net>
- Date: Tue, 30 Sep 2003 12:05:45 +0100
- 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();">... No. 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 from. 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 mouse-click. 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 this: <xforms:trigger id="tr"> <xforms:label>Test</xforms:label> <xforms:message level="modal" ev:event="DOMActivate"> Testing 1 2 3 </xforms:message> </xforms:trigger> And to execute your JavaScript routine, you could add this: <script for="tr" event="DOMActivate" language="JavaScript"> alert('Add some code here'); </script> 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. Regards, Mark Mark Birbeck x-port.net Ltd.
Received on Tuesday, 30 September 2003 07:09:24 UTC