onmousedown is not what I expect in JavaScript

<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.
0
RC
7/26/2006 8:29:18 PM
comp.lang.javascript 38082 articles. 0 followers. javascript4 (1315) is leader. Post Follow

6 Replies
246 Views

Similar Articles

[PageSpeed] 26
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.

0
web
7/26/2006 9:11:14 PM
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/
0
Randy
7/27/2006 1:03:25 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? 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

0
RobG
7/27/2006 5:42:10 AM
RC wrote:
<snip>
> So The implementation for onmousedown in JavaScript is
> different from mousePressed event in MouseListener interface
> in Java.

Richard.

0
Richard
7/27/2006 11:24:58 AM
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/
0
Randy
7/27/2006 9:56:00 PM
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

0
RobG
7/28/2006 12:26:55 AM
Reply:
Similar Artilces:

Expect and terminal problems
I have an expect script, spawned shell etc. I can see on an xterm the following prompt (I have cut off some fragment of this path replacing it with "....", but it was something about 70 characters long - I don't know if this matters): [a_server:user] ~/tmp/..../config > I tried to do "screen -q" and then only read the prompt so that I know that this happened and finished. This is what expect received from the terminal, as logged in "expect -d" mode: expect: does "screen -q\r\r\n\u001b[0m\u001b[H\u001b[J\u001b[H\u001b[J[a_server:user] ~/tmp/..../con...

Need JavaScript based drawing/signature box
I need to be able to create a javascript based drawing/signature box, and be able to save it. Can someone refer me to a script that will allow this, or even a 3rd party package for sale? It can't be Java or ActiveX. Thank you. On Jun 4, 4:59=A0am, javelin <jmevalen...@gmail.com> wrote: > I need to be able to create a javascript based drawing/signature box, > and be able to save it. Can someone refer me to a script that will > allow this, or even a 3rd party package for sale? It can't be Java or > ActiveX. > > Thank you. This can be done with a <canvas>....

TCL + expect
Hello, I have a task (at school) to make an ftp client using linux netcat. I wrote the connection part and some easy commands. Now I need to write the part with ls, get <file> etc. To do this I need to spawn a second instance of netcat that will be listening for data on another port. When it finishes receiving I need to kill it, display the results and GO BACK to my first instance of netcat (the control connection). How can I do that? When I try to spawn a new instance of netcat the old one disappears :( Please help me! Best regards, Peter I figured out something like that: ls ...

Howto: Open a Javascript popup from an external file
Hi, guys: I am not sure if this is doable. In page-1, there is a Javascript onclick event that invoke an pop-up window(this window opens only when clicking a button). and now I want to setup a link from page-2 to open page-1 and directly pop up this window. how can I setup this? I know there is href="javascript:<some code>" which works on the same document? Can I do this to an external files. Many thanks, lihao On Jan 29, 12:53=A0pm, lihao <lihao0...@gmail.com> wrote: > I am not sure if this is doable. In page-1, there is a Javascript > onclick event...

onmousedown onmouseup
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 release. I tried different combinations of onmousedown onmouseup and onclick and putting them in div's img's and anchor's but I can't get it to work, any ideas? <IMG SRC="down.png" alt="fade channel down" onmousedown="javascript:SetDynet('a=<%=a%>&amp;c=<%=x %>&amp;l=0&amp;f=2')" onMouseUp="javascript:SetDyne...

explanation about javascript bytecode opcodes
Hi, While studying the JavaScript engine source code used in Firefox, I am confused about the semantics of various JS bytecode operations given in jsopcode.tbl file (http://mxr.mozilla.org/firefox/source/js/src/ jsopcode.tbl). Is there anyone can provide some pointers to more detailed explanation about those operations? Thanks a lot! Canny Canny wrote: > While studying the JavaScript engine source code used in Firefox, I am > confused about the semantics of various JS bytecode operations given > in jsopcode.tbl file (http://mxr.mozilla.org/firefox/source/js/src/ > jsopcode.tbl)....

FAQ Topic
----------------------------------------------------------------------- FAQ Topic - How can I prevent access to a web page by using javascript? ----------------------------------------------------------------------- In practice you can't. While you could create a suitable encryption system with a password in the page, the level of support you need to do this means it's always simpler to do it server-side. Anything that "protects" a page other than the current one is definitely flawed. -- Postings such as this are automatically sent once a day. Their goal is to answer ...

is there a loadable Expect out there ?
i downloaded windows setup for expect and it works great. i need to load expect as "package require expect" kind'a operation on windows where can i get a "expect.dll" from ? thanks Take a look at http://wiki.tcl.tk/3548 According to Mel <mel.m.heravi@hp.com>: :i downloaded windows setup for expect and it works great. : :i need to load expect as "package require expect" kind'a operation on :windows : :where can i get a "expect.dll" from ? I'm sorry, but your description really confused me. However, if you check http://wiki.tcl...

[Expect] expect THISWILLBENEVERPRINTED the only way to clear the buffer?
What is the most "appropriate" way to clear the buffer not expecting anything special? Say, I have an expect script, which leads two applications simultaneously. If I stop reading from one application, I will block it and this way cause a big problem. I used such a method: I spawn an application on a terminal (by just "sending" to a terminal appropriate command string), then i send 'echo "EXIT STATE = $?"'. When this application finishes, this EXIT STATE = 0 should appear on the console. This is the sign that the application finished and a way to get th...

automate keypress in Expect or TCL
I'm attempting to automate a test script that involves entering a linux box via telnet and walking through a menu system. The only way to exit this menu system is with an f4 key press. I'm pretty new to Expect and TCL. I need the solution to be in Expect or TCL because this .tcl file could be downloaded onto any one of ten pc's, and I don't want to be downloading other software on there as well just to press the F4 key. Is there any simple solution to this? I've been looking at bind and keysym. Could I bind F4 to a key I don't use much...like 'z'? :) Thanks for ...

Async Javascript / Threads
Can someone explains why the following code (taken roughly from Async Javacsript book by Trevor Burnham) behaves differently on jsfiddle.net and jsbin.com ? var start = new Date; setTimeout(function(){ var end = new Date; console.log('Time elapsed:', end - start, 'ms'); }, 5); console.log('wait'); while (new Date - start < 2000) {}; doron.rotem@naturalint.com wrote: > Can someone explains why the following code (taken roughly from Async > Javacsript book by Trevor Burnham) behaves differently on > jsfiddle.net and jsbin.com ...

Sockets: which errors can I expect?
Hi folks, Hope I'm not in the wrong newsgroup with this question :) I'm implementing a multiplexing TCP server in C, using select (on Linux). I am confused about which errors I should expect, and when I would expect them to be raised -- under normal conditions: I'm not talking about out-of-memory errors, not-a-socket errors, and such. The man pages in general only give a big list of sockets-related errors, but no indication of exactly what is raised when. In particular: 1. If recv fails returning -1, what possible values of errno would I subsequently need to cater for, an...

GromJS server-side JavaScript
GromJS server-side JavaScript --------------------------------------------------------------- GromJS is server-side JavaScript implementation of Mozilla SpiderMonkey interpreter. It provides Web designers/programmers ability to use JavaScript object-based code for creating dynamic pages/Web scripts and interact with objects on Web server ie. to manipulate files and directories, handle client-sent data, databases, create content management systems, etc. It includes support for files, SQLite3 database, session variables, hash arrays, HTTP file-upload, cookies, pipes, and many o...

Cross-Browser onmousedown JavaScript
I recently tried the little test page at the bottom of this message. This is what I found out about left button presses. Tested: recent Chrome, Firefox, IE7, Opera, Safari - all on Windows XP Pro Well known, all but IE report on e.which. Less well known: None but Opera passes the mousedown to document. Is this an Opera problem, or is Opera the only one that gets it right? Move the onmousedown assignment (for the div) from JS to the markup and Firefox (only) reports nothing. (No event is passed.) Firefox bug? ---------------------------------------------------- <html> <body> &...

expect user question
Hi, I need to collect "1" or "2" from an user. If user enters any other value, I should display an error message and I should prompt the user again. How can I implement this, Snippet proc getInput {char } { set timeout 100 send_user "$char"; set timeout 5 expect_user { timeout { puts "Restarted \n";exp_continue }; -re "(1|2)\n"; } return $expect_out(1,string); } Try this: proc getInput {prompt} { set timeout 5 while {1} { send_user $prompt expect_user { timeout {puts "Restarted\n"} -re "(1|2...

TypeError: no arguments expected
I havet these 2 files in the same dir. This is code im writing to learn pyt= hong mkoneurl.py: #! /usr/bin/env python import make_ou_class run =3D make_ou_class.makeoneurl() =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D make_ou_class.py: class makeoneurl: def __init__(): self.commandline() def commandline(): com =3D raw_input(":") #Parse out any params and aguements - reg expressions #params[] array to hold paramters par...

Detect onMouseDown during specified time
Hi, I'm creating a program with Delphi 7 that measures the reaction time (RT) of a user when they click a mouse button after stimuli presentation. The stimuli is presented on a form (full-screen) with a TImage and TLabel visible. The correct response can be either the left or right mouse button (depending on specfic cues presented before the stimulus & picked randomly). This process is called a trial, and there are many trials presented one after the other. I am using the QueryPerformanceCounter method to measure the user's RT for each trial (this seems to be the...

An operator is expected here
If( PatternCount(Artist; Tracks::Artist) & Title; Tracks::Album ;"Yes" "No") At the end of this calc? I can't get it to work. I am trying to run two tests for true? On Thu, 03 Mar 2005 15:05:25 GMT, The Wolf wrote: > If( PatternCount(Artist; Tracks::Artist) & Title; Tracks::Album ;"Yes" > "No") If( PatternCount(Artist; Tracks::Artist) & Title; Tracks::Album ; "Yes" "No") Is your if a 'yes', 'no' or 'perhaps'? ;-) > At the end of this calc? I can't get it...

JavaScript A* Path Finding Prototype
This is an A* path finding demo I created a few months ago. I don't see any real uses for it, but it's still neat. http://clindsey.blogspot.com/2008/05/javascript-path-finding-prototype.html On May 6, 5:33=A0pm, DebuggerCLL wrote: > This is an A* path finding demo I created a few months ago. I don't > see any real uses for it, but it's still neat. <snip> "Neat" may be one way of describing a script that pops up the error dialog on IE6 and does nothing else, but it would not be my choice of epithet. I can't duplicate that issue in IE6, WinXP. If an...

parse error, unexpected $, expecting kEND
Does anyone have any techniques or tools that they use to help narrow these down in the code at all? I mean the current method of scanning/folding the code to see if I can tell where the missing 'end' is is a nightmare lol. Of course a working ruby code indenter might help with that but I havent found one of those that works either. -- Posted via http://www.ruby-forum.com/. Slain Wilde wrote: > Does anyone have any techniques or tools that they use to help narrow > these down in the code at all? > > I mean the current method of scanning/folding the code to see if ...

undefined reference ... expected to be defined in a dynamic image
I'm running a Mac: 10.3 with perl 5.8.1. I can't seem to get HTML::parser-3.35 working. Running make seems to be OK--no errors (see below). However, make test spools out the following for each failed test (and they all fail). Some modules seem to install OK, e.g., HTML::Tagset, XML::Simple. Others, e.g., MIME::Base64, fail in a similar manner with the same sort of message-- ".../Base64.bundle... undefined reference... expected to be defined in a dynamic image." I'm new to using perl and its modules, so I suspect I've made some sort of bone-head error. Sorry if I&...

Re: Expecting 0 after calculation... #7 639112
Exactly - I want SAS Institute to make a fundamental change to the language. It's not like they haven't rewritten the whole system all over again several times already. ODS was a pretty big change, perhaps as big as adding a new data type, and that went fairly smoothly. A data step component would not suffice - procs would also need to understand bignums. -- JackHamilton@FirstHealth.com Manager, Technical Development Metrics Department, First Health West Sacramento, California USA >>> "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM> 11/05/2004 3:08 PM >...

Javascript and flash problem
Here is the script I have in my page : <!-- Begin function popUp(URL) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=194,height=146,left = 440,top = 288');"); } // End --> </script> It opens a new window when the user clicks on a certain link. Well, somewhere else in the page, I embeded a flash media object and found out now that everytime the page opens, the pop up window opens too which is NOT what I want. I w...

Problem with using onMouseDown
I'm trying to use onMouseDown to build a certain behavior into a javascript application (see http://groups.google.com/groups?q=Weston+onMouseDown+group:comp.lang.javascript&hl=en&lr=&ie=UTF-8&group=comp.lang.javascript&selm=3febb6e5%240%24201%2475868355%40news.frii.net&rnum=1 for the gory details, but essentially I want a pop-up menu to appear when I hold the mouse down on an image element for at least one second). However, I'm finding that Mozilla pops up its own menu when I do this, which will definitely get in the way of my own pop up. How do I get around th...

changing or at least detecting character encoding via javascript ?
Hi all, I have a question if it is possible to manipulate the settings of character encoding in Ms Internet Explorer 5.0, 5.5 and 6.0. The problem is that the default instalation of Ms IE seems to have hard selected default encoding to "Western European (ISO)", which means iso-8859-1. When browsing pages with some Central/Eastern European characters these are converted to iso-8859-1 so displayed wrong. I would suppose the "auto-select" option should be default, so the browser can select the right encoding according to the meta-tags in the head of webpage. But this is appa...