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

Re: Defining "onClick"-Events in XForms Controls

From: Steven Pemberton <steven.pemberton@cwi.nl>
Date: Thu, 9 Oct 2003 23:09:00 +0200
Message-ID: <053701c38ea9$92bcf4a0$df13fea9@srx41p>
To: "Roman Huditsch" <roman.huditsch@hico.com>, <www-forms@w3.org>

From: "Roman Huditsch" <roman.huditsch@hico.com>

> 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! (By the way, onClick is a bit of code, not a URL, so it should read

    onclick="test();"

)

> or is there a better way to maybe omitt the "html:onClick" attribute?

Very much better.

<trigger>
    <label>Test</label>
    <html:script ev:event="DOMActivate"
type="text/javascript">test();</script>
</trigger>

would do nicely, assuming your host document markup allowed this, or

    <trigger ev:event="DOMActivate" ev:handler="#test">
        <label>Test</label>
    </trigger>

where '#test' identifies a script element with id="test" that calls test();.

The XML Events method of doing what Mark Birbeck suggested

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

is:

    <script ev:observer="tr" ev:event="DOMActivate" type="text/javascript">
        test();
    </script>

Then the trigger would look like this:

    <trigger id="tr">
        <label>Test</label>
    </trigger>

This would indeed allow you to have more than one handler for the same
event, as would the most general solution:

    <ev:listener event="DOMActivate" observer="tr" handler="#test"/>

where the script element has id="test".

Steven Pemberton
Received on Thursday, 9 October 2003 17:09:14 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 10 March 2012 06:21:56 GMT