event

  • Revision slug: Talk:Document_Object_Model_(DOM)/event
  • Revision title: event
  • Revision id: 164214
  • Created:
  • Creator: Nickolay
  • Is current revision? No
  • Comment

Revision Content

There needs to be a section on how HTML event attribute strings are evaluated. For ex:

<button ... onclick="foo();">

creates a function named "onclick" with the event object as a parameter named event:

function onclick(event) {
   foo();
}

See Core_JavaScript_1.5_Reference:Objects:Function#Functions_as_event_handlers.

--Maian 03:30, 8 September 2005 (PDT)

Actually, onclick="foo();" will assign the RESULT of the function "foo" to onclick, unless I am misunderstanding something. --Callek 20:20, 15 September 2005 (PDT)
You're misunderstanding something :) That would make no sense, since most handlers return either nothing (undefined) or a boolean, and you don't set onclick to undefined or boolean. Try alert(button.onclick) for proof. --Maian 00:15, 16 September 2005 (PDT)
Do NOTE my use of () in the "actually" clause there, button.onclick is different from button.onclick(); as in, adding the paren's to the attribute changes its meaning, I'll check this out for sure later, been a while since I played with the HTML side of any script-related pages. Though realize, if I was 100% sure, I would have simply fixed any problem I found. --Callek 22:45, 20 September 2005 (PDT)
Callek, in your example, "foo()" is a string, so you're really misunderstanding (or mistyping) something. --Nickolay 02:31, 21 September 2005 (PDT)

Revision Source

<p>There needs to be a section on how HTML event attribute strings are evaluated. For ex:
</p>
<pre>&lt;button ... onclick="foo();"&gt;
</pre>
<p>creates a function named "onclick" with the event object as a parameter named <code>event</code>:
</p>
<pre>function onclick(event) {
   foo();
}
</pre>
<p>See <a href="en/Core_JavaScript_1.5_Reference/Objects/Function#Functions_as_event_handlers">Core_JavaScript_1.5_Reference:Objects:Function#Functions_as_event_handlers</a>.
</p><p>--<a href="User:Maian">Maian</a> 03:30, 8 September 2005 (PDT)
</p>
<dl><dd> Actually, onclick="foo();" will assign the RESULT of the function "foo" to onclick, unless I am misunderstanding something. --<a href="User:Callek">Callek</a> 20:20, 15 September 2005 (PDT)
</dd></dl>
<dl><dd><dl><dd> You're misunderstanding something :) That would make no sense, since most handlers return either nothing (undefined) or a boolean, and you don't set onclick to undefined or boolean. Try <code>alert(button.onclick)</code> for proof. --<a href="User:Maian">Maian</a> 00:15, 16 September 2005 (PDT)
</dd></dl>
</dd></dl>
<dl><dd><dl><dd> Do <b>NOTE</b> my use of () in the "actually" clause there, button.onclick is different from button.onclick();  as in, adding the paren's to the attribute changes its meaning, I'll check this out for sure later, been a while since I played with the HTML side of any script-related pages. Though realize, if I was 100% sure, I would have simply fixed any problem I found. --<a href="User:Callek">Callek</a> 22:45, 20 September 2005 (PDT)
<dl><dd> Callek, in your example, <code>"foo()"</code> is a string, so you're really misunderstanding (or mistyping) something. --<a href="User:Nickolay">Nickolay</a> 02:31, 21 September 2005 (PDT)
</dd></dl>
</dd></dl>
</dd></dl>
Revert to this revision