Swapping the onClick method

O

Olumide

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

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){
//DO SOMETHING ELSE
]

/////////////////////////////////


ThanX

- Olumide
 
L

Lasse Reichstein Nielsen

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

What is a "layer"? I will assume you don't mean the <layer> element
from Netscape 4 said:
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

Yes, you call the function and assing the return value, you don't
assign the function itself.
my browser (IE6.0) reports an error.

The error would be nice to have, it would remove the need for guessing,
and thereby the risk of guessing wrong.
Is this the correct way to perform the such an assignment?

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.
/L
 
O

Olumide

What is a "layer"? I will assume you don't mean the said:
from Netscape 4, but just a plain <div> element.

I'm using the plain said:
The error would be nice to have ...

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
 
R

Randy Webb

Olumide said:
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

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){
return;
}
else{
working = true;
//do your shrinking/enlarging here
working = false;
}
}
 
T

Thomas 'PointedEars' Lahn

Olumide said:
The problem is that I am using the setTimeout("function()", timeStep)
method - to perform the animation. When I set timeStep to a
relatively large value such as 50ms, the code works. When however I
set it much lower, the code does not work! AARRGHHHH!!!

Anyone got ideas?

Do not use timeouts/intervals below 50 ms,
they are known to be unreliable.


PointedEars
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
Thomas 'PointedEars' Lahn
Do not use timeouts/intervals below 50 ms,
they are known to be unreliable.

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).
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top