addEventListener parameters

Hi Everyone,

Is there a way to send parameters to the function being added to an event with addEventListener.

I.E.

say you have this function


function someFcn(i){
 alert(i);
}

and I add it to an object.


someElement.addEventListener('focus', someFcn, false);

Is there a way to send a parameter to someFcn.
For Example I have tried this but it failed


var someString = 'Hello World';
someElement.addEventListener('focus', someFcn(someString), false);

Thanks for any help,

Nick

That will not work unless someString is a variable in the global scope. You have to do this:

var someString = 'Hello World';
someElement.addEventListener('focus', function() {
  someFcn(someString);
}, false);

Raffles,

I would like to add to this thread.
Is there a fundemental difference between:

someElement.addEventListener(‘focus’,function)

and:

someElement.attachEvent(“onmouseover”, function)

Is the second one IE only?

Thanks

Yes, the second one is IE only. The first one, addEventListener, should also have a third parameter (true or false), which specifies whether to add the listener in the bubbling or capturing phase. This is a good page to read about these two: http://www.quirksmode.org/js/events_advanced.html