- From: Johnny Stenback <jst@netscape.com>
- Date: Tue, 28 Jan 2003 18:09:37 -0800
- To: Amy Lee <amy@avantgo.com>
- CC: www-dom@w3.org
Amy Lee wrote:
> My script is as follows. Can I use the event type of
> addEventHandler as onEventHandlers like Q1 and Q2 instead of using
> "click" or "focus"? This script doesn't work under Netscape but if
> I change it to "click" or "focus", that will work. I am just
> wondering which way is right since the spec is not clear to me. I
> would appreciate if anybody can answer especially any W3 members.
> Thanks!
I assume you're asking if addEventListener('onclick', ...) or
addEventListener('click', ...) is the right thing to do, if so, the
answer is that addEventListener('click', ...) is the way to go. The on*
names are just the names of the event handler attributes in HTML markup,
and the names of the event handler properties in web browsers that
support DOM0 (the defacto pre-DOM Level 1 'standard').
>
> <html>
>
> <head>
>
> <title>DOM addEventListener </title>
>
> <script>
>
>
> // Event Registration Example
>
>
> function l_func() {
>
> button = document.getElementById("mybutton");
> button.value = "clicked";
> }
>
> function load() {
>
> button = document.getElementById("mybutton");
> button.addEventListener("onclick", l_func, false);
> ----------------------------------->Q1
> button.click();
>
> if(button.value == "clicked")
> {
> body = document.getElementById("mybody");
> text = document.createTextNode("PASSED");
> body.appendChild(text);
>
> }
>
> else
> {
>
> body = document.getElementById("mybody");
> text = document.createTextNode("FAILED");
> body.appendChild(text);
>
> }
>
> }
>
>
> function l_func2() {
>
> text = document.getElementById("mytext");
> text.value = "hi";
>
> }
>
> function load2() {
>
> text = document.getElementById("mytext");
> text.addEventListener("onfocus", l_func2, false);
> ------------------------------Q2
> text.focus();
>
> }
>
> </script>
>
> </head>
>
> <body id="mybody" onload="load();load2();" >
>
> <input type="button" value="Button" id="mybutton">
> <input type="text" value="Text" id="mytext"><br>
> <b>Try this on Netscape. This doesn't work under IE.</b>
> <hr>Test status:
>
> </body>
>
>
> </html>
>
--
jst
Received on Tuesday, 28 January 2003 21:10:23 UTC