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

Kowalkowski, Lee (ASPIRE) lee.kowalkowski at hmrcaspire.com
Wed Aug 31 04:03:03 CDT 2005


> -----Original Message-----
> From: Matt Warden [mailto:mwarden at gmail.com]
> Sent: Tuesday, August 30, 2005 8:16 PM
>
> This is the equivalent of having inline CSS.

No it isn't, having onsubmit="if(this.fieldName.value === ''){alert('you
must enter something');return false;}" is the equivalent of having inline
CSS.  A single method call is the equivalent of using a stylesheet.  

If you don't see it that way I fear you're over-engineering the problem, at
great cost, for a merely academic benefit.

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

How does it have nothing to do with markup?  If I have <form
name="myForm">...</form>, how is document.myForm *not* a reference to it?
I'd really like to know.

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

Eh?  I wasn't talking about *onload* being the reason for the coupling.  I
said stripping all your event handler references out of the HTML markup is
bad.  Think about it.  The event handlers are the interface to JS provided
by the HTML specification, you rarely need to write your own.  You can
easily provide a different implementation by swapping out the included JS
file for another, just like you can with css files.  

If all your JS events are being injected at parse / onload time (not
bothered which, it's still run-time), you're getting JS to boot-strap itself
which doesn't make much sense to do without a good reason.  Don't get me
wrong, there are valid scenarios, for example, if your page doesn't degrade
acceptably in a non-JS browser, or if you have a generic script which is
flexible enough to plug itself into whatever page it's included.  That's
brilliant, but to do it all the time?  You're having a laugh!

- LK


===========================================================
Our e-mail domain has now changed from iraspire.com to hmrcaspire.com. Please update your address books.
===========================================================



More information about the thelist mailing list