views:

45

answers:

1

Hi,

I can see how to attach an event to an object that has no parameters and no return value but how to modify the code below to attach a listener that takes parameters and returns a value?

     function attachEventListener(target, eventType, functionRef,
    capture)
    {
    if (typeof target.addEventListener != "undefined")
    {
    target.addEventListener(eventType, functionRef, capture);
    }
    else if (typeof target.attachEvent != "undefined")
    {
    target.attachEvent("on" + eventType, functionRef);
    } 
attachEventListener(mylink, "click", ClickMe, false);

I get no error when I do this but it also doesn't fire the event when the link is clicked eithier, Note my functionRef is in this form Test(true, "Hello!"):

target.attachEvent("on" + eventType, function() {functionRef});

Thanks!

A: 
attachEventListener(myLink, 'click', function(foo, bar) { alert('yay! ' + foo); }, false);
Mathias Bynens
How to return a value? For some reason I can't just add return in front of function.
OutOFTouch
I keep getting a type mismatch when trying to attach the functionI am building the function call from variable parameters including the name of the function.
OutOFTouch
Just replace `alert()` with `return`… Posting your HTML + JS source might help track down the problem.
Mathias Bynens
OK I got it working ty.
OutOFTouch