Swapping the onClick method

Discussion in 'Javascript' started by Olumide, Feb 28, 2004.

  1. Olumide

    Olumide Guest

    I need to swap the onclick method bound to a layer (nLayer). The

    document.getElementById('nLayer').onclick = nullScript; // OK

    works when the method bound (i.e. nullScript) requires no arguments.
    However, when the method to be bound (i.e. activeScript) DOES require
    an argument as show below,

    document.getElementById('nLayer').onclick = activeScript(1); // ERROR

    my browser (IE6.0) reports an error. Is this the correct way to
    perform the such an assignment?

    ////// Function Declarations /////

    function nullScript(){
    //DO STUFF

    function activeScript(var number){



    - Olumide
    Olumide, Feb 28, 2004
    1. Advertisements

  2. What is a "layer"? I will assume you don't mean the <layer> element
    Yes, you call the function and assing the return value, you don't
    assign the function itself.
    The error would be nice to have, it would remove the need for guessing,
    and thereby the risk of guessing wrong.
    Not if I guess what you want correctly. You would probably want to do:
    document.getElementById('nLayer').onclick =
    function() {activeScript.call(this,1);}

    Remember that all other browsers sends an argument to the handler: the
    event being handled.
    Lasse Reichstein Nielsen, Feb 28, 2004
    1. Advertisements

  3. Olumide

    Olumide Guest

    All I got was an "Error on page message" (with the yellow caution in
    the status bar. The only error reported was an "Object required"
    messge, Code 0). In the NN 6 JavaScript console however, I got the
    message: document.getElementById(layerID) has no properties. ... Not
    very helpful.

    Perhaps I should explain what I'm trying to do. My page uses animated
    icons that shrink and disappear when you click them, while the
    previously selected icons "pops" out. What I'm trying to do is to
    prevent the user from clicking on a new icon before the current icon
    disappers, or at least make such clicks "impotent". My plan is to
    (temporarily) replace all onclick handers with a dummy script while
    the clicked icon shrinks. The onclick handler is to be replaced with
    the former handler once the animation is complete.

    Please tell me I'm making sense ...

    - Olumide
    Olumide, Feb 29, 2004
  4. Olumide

    Randy Webb Guest

    Have a global variable that tracks when one icon is shrinking or
    enlarging. Then, whenever an icon is clicked - set the variable. When
    its finished shrinking/enlarging, reset it. Have the function check that
    variable and if its shrinking/enlarging then return.

    var working = false;
    function shrinkIcon(){
    if (working){
    working = true;
    //do your shrinking/enlarging here
    working = false;
    Randy Webb, Feb 29, 2004
  5. Do not use timeouts/intervals below 50 ms,
    they are known to be unreliable.

    Thomas 'PointedEars' Lahn, Apr 7, 2004
  6. JRS: In article <>, seen in
    Thomas 'PointedEars' Lahn
    Is there independent evidence for that?

    Remember that timeouts will be inexact, since they can only fire in a
    timer tick, which is 54.9 ms on some systems and 10 ms on others; that
    is not unreliability, but may be unfitness for purpose.

    Again, the predecessor posts are ancient; I retain for 17 days at
    present, and no longer have them. A dated attribution line would have
    made the matter clear (Google M-IDs include YYMMDDhhss).
    Dr John Stockton, Apr 8, 2004
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.