[thelist] [JavaScript] Event question for you event experts

Matt Warden mwarden at gmail.com
Mon Feb 20 13:42:09 CST 2006


Tom,

On 2/20/06, Tom Dell'Aringa <pixelmech at yahoo.com> wrote:
> thing one might do in this case - built an init function and did like so:
>
> function initPage()
> {
>   addFocusControls();
>   isErrors();
>   buttonState();
> }
>
> window.onload = initPage;

This will work, but it becomes very very hairy once you start breaking
code out into their own external javascript, each of which needs to
attach one or more events onto onload.

Take a look at this:

http://mwarden.f2o.org/sandbox/viewsource.php?linemode=0&f=eventlistener2.js

> var myInput = document.getElementById('myTextInput');
> myInput.addEventListener("load", function(e){ //stuff here }, false);
>
> But the problem is the event listener can only be applied to myInput AFTER the onLoad event...
> sooo... how can it listen for onload!?!? I seem to be caught in a circle here.

I wouldn't say that attaching this to window.onload is bad,
necessarily. Anyway, take a look at this:

http://developer.yahoo.net/yui/event/index.html

It will allow you to attach an effent to an element as soon as it's
available to DOM.

--
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the thelist mailing list