[thelist] Events
Dougal Campbell
dougal at gunters.org
Fri Nov 1 13:54:01 CST 2002
On Fri, 1 Nov 2002, Diego wrote:
> > > I have a number of elements on a page, each with an id. I
> > > want certain javascript functions to fire on certain events,
> > > but I don't want to specify event handlers in any tags nested
> > > within (but not including) the body. If I have a function
> > > Init() that fires on page load, is there some way I can do
> > > the following (the code is incorrect and for illustrative
> > > purposes only):
> > >
> > > 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
>
> regards,
> Diego.
And you need to define it as a function:
foo.onclick = function { alert("Eureka!") }
or
function fooClick() {
alert("Eureka!")
}
foo.onclick = fooClick
--
Ernest MacDougal Campbell III, MCP+I, MCSE <dougal at gunters.org>
http://dougal.gunters.org/ http://spam.gunters.org/
Web Design & Development: http://www.mentalcollective.com/
This message is guaranteed to be 100% eror frea!
More information about the thelist
mailing list