[thelist] javascript default event handlers, default events. [TIP]

Matt Warden mwarden at gmail.com
Tue Aug 30 14:15:30 CDT 2005


Lee,

On 8/30/05, Kowalkowski, Lee (ASPIRE) <lee.kowalkowski at hmrcaspire.com> wrote:
> If I have <form onsubmit="return validate(this)">, have I separated
> behaviour from markup?  Almost; the behaviour is in the validate function,
> but my markup contains an invocation.

This is the equivalent of having inline CSS.

> If I change it to do the javascript: document.myForm.onsubmit =
> myFormValidation, have I separated behaviour from markup?  Not as much - I
> have an explicit markup reference to "myForm" to which I am programmatically

That is not a markup reference. It has nothing to do with markup.

> I also have to ensure I get my timing right so
> I don't try to define the onsubmit handler before myForm has been parsed,
> which means for a short time, myForm does not have an onsubmit event
> handler.  Onload events can take a while to trigger, especially if there's
> something on the page taking a long time to load.

That's why onload events are less than ideal. There are solutions that
do not require window.onload (JSAN just released DOM.Ready, but they
are still working through some issues). Admittedly, I tend to ignore
these solutions, but then again I tend not to work on sites that have
20 3rd-party banners and iframes and...

> So after doing this, the behaviour and markup are more closely coupled!  How
> Ironic.

I strongly disagree. onload is event-based, as are the other methods
that avoid onload. Again, this doesn't have anything to do with
markup.



-- 
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