473,473 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Swapping the onClick method

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
Jul 20 '05 #1
5 1459
50***@web.de (Olumide) writes:
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, but just a plain <div> element.
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
> What is a "layer"? I will assume you don't mean the <layer> element
from Netscape 4, but just a plain <div> element.
I'm using the plain <div> element.
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
Jul 20 '05 #3
Olumide wrote:
What is a "layer"? I will assume you don't mean the <layer> element
from Netscape 4, but just a plain <div> element.

I'm using the plain <div> element.

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


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;
}
}

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 20 '05 #4
Olumide wrote:
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
Jul 23 '05 #5
JRS: In article <40**************@PointedEars.de>, seen in
news:comp.lang.javascript, Thomas 'PointedEars' Lahn
<Po*********@web.de> posted at Wed, 7 Apr 2004 21:00:11 :
Olumide wrote:
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.


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

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Christopher Jeris | last post by:
Please help me understand the differences, in semantics, browser support and moral preferredness, between the following three methods of swapping content in and out of a page via JavaScript. I...
4
by: alanrn | last post by:
I am using a TreeView to display the hierarchy of a strongly-typed collection (inherited from CollectionBase). The order of the nodes in the TreeView is strictly tied to the order in which they...
7
by: Jon Glazer | last post by:
I know this is sorta reposting but I want to simplify the issue a bit. Take the following script: function replacemain(s){ var x = document.images; var y = document.images; var pictemp =...
10
by: VA | last post by:
I got the following function to swap table columns from somewhere on the Internet function swapColumns (table, colIndex1, colIndex2) { if (table && table.rows && table.insertBefore && colIndex1...
2
by: Sam Marrocco | last post by:
Does anyone know of a method of swapping collection items? For example: Current collection: ..Item(1)="a" ..Item(2)="b" ..Item(3)="c" After swapping items 2 and 1.... ..Item(1)="b"...
9
by: storyGerald | last post by:
I knew some ways of swapping two ints without using a temporary variable. Just like: // Method 1: void swap1(int &a, int &b) { int temp = a; a = b; b = a; }
2
by: gimme_this_gimme_that | last post by:
Suppose I have: <div id="d1"> asdfas </div> <div id="d2"> asdfasf asdf </div>
3
by: Geoff Cox | last post by:
Hello, Way back in 2000 Ken Cox put up this code for swapping images on a button. I cannot work out how to use it so that more than 1 button can use it. I guess the problem is knowing how to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.