[thelist] Events

.jeff jeff at members.evolt.org
Fri Nov 1 15:09:01 CST 2002


chris & diego,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Diego
>
> > > function Init() {
> > >   var foo = document.getElementById("bar");
> > >   foo.onClick = alert("Eureka!");
> > > }
>
> Yes it can be done, only you need to write "onclick",
> not "onClick", which will throw an error. The same
> goes for "onMouseOver" (element.onmouseover),
> onmouseout, onload, onunload, etc
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

additionally, you can't pass arguments in the function assignment.  so, the
following would not work:

foo.onclick = alert('Eureka!');

however, supposing you had a function called fooOnclick(), you could do
this:

foo.onclick = fooOnclick;

or, you could write your own anonymous function as the value of the onclick
event handler, like this:

foo.onclick = function()
{
  alert('Eureka!');
  return false;
}

if you use the "this" keyword within the anonymous function, you'll have an
object reference to the element the click event fired on.  btw, the syntax
above is the same as this:

<foo onclick="alert('Eureka!'); return false">

good luck,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/





More information about the thelist mailing list