events and parameters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • oeyvind toft

    #1

    events and parameters

    myObj.onmouseov er = someFunction;

    How can I set up this so myObj can send parameters to the function ?

    Oeyvind

    --





  • Michael Winter

    #2
    Re: events and parameters

    On Tue, 12 Oct 2004 21:08:59 +0200, oeyvind toft <oeyvtoft@onlin e.no>
    wrote:
    [color=blue]
    > myObj.onmouseov er = someFunction;
    >
    > How can I set up this so myObj can send parameters to the function ?[/color]

    An element doesn't "send" anything to its event listeners. The browser
    calls listeners directly, using the element to obtain a reference for use
    with the this operator.

    As for calling a function with arguments, you'll have to introduce an
    intermediate function which is called as the listener. It can then call
    someFunction, in turn. For example,

    myObj.onmouseov er = function(e) {
    someFunction(
    this, // reference to myObj
    e || event // event object
    );
    };

    creates an anonymous function which is added as the mouseover listener for
    myObj. When called, the this operator will refer to myObj, and on
    DOM-compliant browsers, e will be the event object.

    Hope that helps,
    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.

    Comment

    • oeyvind toft

      #3
      Re: events and parameters

      Thanks Michael

      Just what I was looking for...

      Oeyvind

      --



      Comment

      Working...