473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

onmousedown is not what I expect in JavaScript

RC
<a href="#" onmousedown="callMyFunction()">Press the mouse button</a>

What I expect is when I or an user move mouse pointer over that link,
and press the mouse button. Then will "callMyFunction()" over and
over again until I release the mouse button (mouseup).

But what I found out the onmousedown is just acts the same as onclick.
It only "callMyFunction" once. If I want to call again, I need to
keep repeat mousedown, mouseup like clicking. That is not cool at all!

So The implementation for onmousedown in JavaScript is different from
mousePressed event in MouseListener interface in Java.
Jul 26 '06 #1
6 4703

RC wrote:
<a href="#" onmousedown="callMyFunction()">Press the mouse button</a>

What I expect is when I or an user move mouse pointer over that link,
and press the mouse button. Then will "callMyFunction()" over and
over again until I release the mouse button (mouseup).

But what I found out the onmousedown is just acts the same as onclick.
It only "callMyFunction" once. If I want to call again, I need to
keep repeat mousedown, mouseup like clicking. That is not cool at all!
Why not implement it so that once they click, your function will
continuously be called. However, on an onmouseout event, you can make
it so that the "callMyFunction" function stops being called.
So The implementation for onmousedown in JavaScript is different from
mousePressed event in MouseListener interface in Java.
Probably, since Java != JavaScript.

Jul 26 '06 #2
RC said the following on 7/26/2006 4:29 PM:
<a href="#" onmousedown="callMyFunction()">Press the mouse button</a>

What I expect is when I or an user move mouse pointer over that link,
and press the mouse button. Then will "callMyFunction()" over and
over again until I release the mouse button (mouseup).

But what I found out the onmousedown is just acts the same as onclick.
It only "callMyFunction" once. If I want to call again, I need to
keep repeat mousedown, mouseup like clicking. That is not cool at all!

So The implementation for onmousedown in JavaScript is different from
mousePressed event in MouseListener interface in Java.
onmousedown="callMyFunction()"
onmouseup="var keepCallingIt = false"
onclick="return false"
var keepCallingIt = true;
function callMyFunction(){
//code here for callMyFunction
if(keepCallingIt){
callMyFunction()
}
}

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 27 '06 #3

Randy Webb wrote:
RC said the following on 7/26/2006 4:29 PM:
<a href="#" onmousedown="callMyFunction()">Press the mouse button</a>

What I expect is when I or an user move mouse pointer over that link,
and press the mouse button. Then will "callMyFunction()" over and
over again until I release the mouse button (mouseup).

But what I found out the onmousedown is just acts the same as onclick.
It only "callMyFunction" once. If I want to call again, I need to
keep repeat mousedown, mouseup like clicking. That is not cool at all!

So The implementation for onmousedown in JavaScript is different from
mousePressed event in MouseListener interface in Java.

onmousedown="callMyFunction()"
onmouseup="var keepCallingIt = false"
onclick="return false"
var keepCallingIt = true;
function callMyFunction(){
//code here for callMyFunction
if(keepCallingIt){
callMyFunction()
}
}
Wont that create a deeply recursive function? If the mouse button is
held down for some time, it will likley cause a problem.

It may be better to use setTimeout onmousedown, then cancel it
onmouseup, e.g.:

<script type="text/javascript">

var pageCounter = (function(){
var isRunning;
return {
start : function(){
var d = document.getElementById('xx');
d.innerHTML = +d.innerHTML + 1;
isRunning = setTimeout('pageCounter.start();', 100);
},
stop : function (){
if (isRunning) clearTimeout(isRunning);
}
}
})();

</script>

<a href="#"
onmousedown="pageCounter.start();"
onmouseup="pageCounter.stop();"
>start/stop</a>
<div id="xx">0</div>

--
Rob

Jul 27 '06 #4
RC wrote:
<snip>
So The implementation for onmousedown in JavaScript is
different from mousePressed event in MouseListener interface
in Java.
Richard.

Jul 27 '06 #5
RobG said the following on 7/27/2006 1:42 AM:
Randy Webb wrote:
>RC said the following on 7/26/2006 4:29 PM:
>><a href="#" onmousedown="callMyFunction()">Press the mouse button</a>

What I expect is when I or an user move mouse pointer over that link,
and press the mouse button. Then will "callMyFunction()" over and
over again until I release the mouse button (mouseup).

But what I found out the onmousedown is just acts the same as onclick.
It only "callMyFunction" once. If I want to call again, I need to
keep repeat mousedown, mouseup like clicking. That is not cool at all!

So The implementation for onmousedown in JavaScript is different from
mousePressed event in MouseListener interface in Java.
onmousedown="callMyFunction()"
onmouseup="var keepCallingIt = false"
onclick="return false"
var keepCallingIt = true;
function callMyFunction(){
//code here for callMyFunction
if(keepCallingIt){
callMyFunction()
}
}

Wont that create a deeply recursive function?
Absolutely <g>
If the mouse button is held down for some time, it will likley cause a problem.
It's not "likely", rather its pretty dependable.
It may be better to use setTimeout onmousedown, then cancel it
onmouseup, e.g.:
Depending on what you want. At 13ms timeout, you can only execute it
once every 13ms, whereas with the recursion it happens as fast as the
processor can process the script.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 27 '06 #6

Randy Webb wrote:
RobG said the following on 7/27/2006 1:42 AM:
[...]
Wont that create a deeply recursive function?

Absolutely <g>
Firefox seems to allow 1,000 recursions before a 'too much recursion'
error occurs. Maybe there's a setting somewhere to change that... ;-p

If the mouse button is held down for some time, it will likley cause a problem.

It's not "likely", rather its pretty dependable.
And pretty quick - a simple script does it in less than 10ms.

It seems to me that whatever is kicked-off by the mousedown event hogs
the one and only JS thread (in Firefox and IE at least), so the mouseup
event is qued and can't interup the process started by the mousedown.

To 'work', the script must come up for air to see if some other event
wants to do something, setTimeout (or maybe setInterval) seem to be the
only way to do that.

It may be better to use setTimeout onmousedown, then cancel it
onmouseup, e.g.:

Depending on what you want. At 13ms timeout, you can only execute it
once every 13ms, whereas with the recursion it happens as fast as the
processor can process the script.
If the minimum interval is 13ms (or whatever, I guess it's
implementation dependent) then that is as fast as you can do it. Other
choices are to either wait for a 'too much recursion' error or a 'this
script is taking too much time' message.

Maybe they suit the OP better :-)
--
Rob

Jul 28 '06 #7

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

Similar topics

1
by: Jerry O | last post by:
Hi, I am having trouble implemeting the OnMouseDown event in NN4.7 when used on a Input of type image. It works in Mozilla and N6.2 Is this a limitation or is there a workaround Thanks,
1
by: Weston C | last post by:
I'm trying to use onMouseDown to build a certain behavior into a javascript application (see...
6
by: Gary Mayor | last post by:
Hi, I'm trying to make it so when I click a image it prints out the image again and a load of other stuff. So far i've got this far. <html> <head> <script language="JavaScript" type="">...
1
by: sameth | last post by:
I wrote a script that uses onmousedown and onmouseup in javascript that works great in ie and firefox on windows2000. It looks as if the pocketpc 2003 ie browser dosn't support onmousedown or...
2
by: stef | last post by:
Hello: I would like a process to continue as long as the mouse is held down on a button and to stop as soon as it is released. Something ideally like this: "while (ButtonIsDown) {i+ = 1}" I...
3
by: walkerfx | last post by:
Hi All, Is there a way to access the value assigned to onmousedown for an object? I've been searching online but can only seem to find how it is assigned via html. What I need to do is access...
9
by: jon | last post by:
Hello, I'm trying to experiment with some javascript to do some custom dragdrop handling. I wish to use the onMouseDown event to trigger the start of my drag, and onMouseup for a potentential...
1
by: NeilCarmichael | last post by:
I am flummoxed, I'm relatively new to javascript and I can't get my onmousedown onmouseup script to work. simply, I want to fire one function when I click down on a graphic and a second when I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.