cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Johnston <jjohns...@apache.org>
Subject Re: bug with double-listbox?
Date Fri, 07 Nov 2008 15:03:48 GMT
On 11/06/2008 06:05 PM, Paul Joseph wrote:
> But if I have a JavaScript function say:
>
> function myFunction() {
> alert ("loaded");
> }
>
> and if I call this function on page load either by using
> window.onload=myFunction;
>
> OR by
> <body onLoad="javascript:scrollToPosition();">
>
> then the double-list box stops working.


This is most likely because CForms adds its own initialization function 
using the same onload property, so adding yours overwrites it.

Nowadays it's best practice to avoid using on[event] properties, and use 
instead the DOM2 event methods (forking for IE's nonstandard event 
model.)  Any of the common javascript libraries will handle this for you 
behind the scenes, or you can write a simple abstraction function:

function addEvent( element, type, handler ) {
     if( element.addEventListener ) {
         element.addEventListener( type, handler, false );
     } else {
         element.attachEvent( 'on' + type, handler );
     }
}

addEvent( window, 'load', myFunction );
addEvent( window, 'load', myOtherFunction );
//etc...

This allows you to add as many listeners as you want rather than being 
limited to one.

--Jason





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message