onmousedown is not what I expect in JavaScript

  • Permalink
  • submit to reddit
  • Email
  • Follow


<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
Reply RC 7/26/2006 8:29:18 PM

See related articles to this posting

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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply RobG 7/28/2006 12:26:55 AM
comp.lang.javascript 37746 articles. 15 followers. Post

6 Replies
157 Views

Similar Articles

[PageSpeed] 44

  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Javascript object expected error
I had this web site working without problems a day ago. I went to add some images on one of the pages in my site and now the index.html page is popping up error messages when ever the page loads in IR6 ! If anyone can asssit me on this i would appreciate it . the URL is : terroratthewestwood.com, i havent tried it in netscape but in opera it doesnt give me an erorr box, its just that the script on the images page ("URL/gallery.html") doesnt work at all.....i am a script beginner so excuse me if this is a dumb question.... "matt" <mesh@buckeye-express.com> wrote in...

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

Troubleshooting Javascript. Object Expected.
I've got some javascript that works great in some old asp.net 1.0 inline code. I'm attempting to move the javascript to an asp.net masterpage and use it in a content page. I understand this is not an asp.net forum. I'm looking at the rendered page and am not sure why i'm getting that common Object expected message. But mainly my question is about troubleshooting javascript in general. What tools do you use? is there a console of IE to figure out where this error is happening exactly What it's suppose to do is display an image, and then do a slideshow (blending) of 5 im...

In Internet Explorer JavaScript does not show what is expected.
Hi, On my web-site I use javascript to hide-show text fields. All text- fields are hidden by default. User can display text-field by clicking ">>". And then user can hide the text-filed by clicking "<<". In Firefox everything works as described. However, in the IE instead of "<<" I see only "<". Can anybody help me to fix the bug. The site is here: http://www.infoment.org/index.php?q=72.174 Thank you in advance. On Jan 20, 1:20=A0pm, inforonm...@gmail.com wrote: > Hi, > > On my web-site I use javascript to hide-show tex...

javascript strings not 7 bit like I expected
I'd always been under the misimpression that JavaScript strings were 7-bit ASCII like C strings and the issue had never come up before. It seems that I'm wrong (happily). Does anyone know if I can assume this will work regardless of code page, HTML doctype, quirks mode etc? Is it only because I've made this a super simple page running on Windows XP US-en that this works? Would it fail in a lot of configurations (e.g. Mac, Linux, Asian codebases) ? <html> <body> <script> var s="Hell� W�rld"; document.write(s); alert(s); </script> </body>...

javascript "Error: Expected ';'"
Hi there, I am driving myself crazy over this problem. I have used this very same function in another page without any problems, but now I am experiencing the "Error: Expected ';'" when i try and run it, and it doesn't fire (obviously, because there is an error). The code is: function SetDetailValue(i) { opener.document.<%=Request("tbm")%>.value = i; window.close(); } the variable i is passed a string ('d1','d2' etc) The error occurs (apparently) on the first line. Please will someone help me with this. I think maybe I am making a...

Confused by a javascript problem, event handlers not working as expected/desired
Hello, I have been modifying some javascript shopping basket code and have run into a problem. I have produced a subset of the HTML/JS that shows the problem and placed it here: http://dusrc.org/js_test.html The problem is described on that page but basically 2 event handlers are being called when I would expect just one to be called. If someone could explain what I am doing wrong then I would be very grateful. Thanks Deryck 1) <input type="image"> is equal by functionality to <input="submit"> (except it lets you track the click coords within the i...

Javascript Object Expected error ASP.NET 2.0 OnkeyPress
I have a very simple asp.net 2.0 page with one textbox that onkeyPress is suppose to do some check of what was typed. Below is the source showing the javascript function is available. The minute I strike a key I get the error. Anybody know why? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script language="javascript" type="text/javascript "> function ValidateNumeric() { var keyCode = window.event.keyCode; if (keyCode > 57 || keyCode < 48) ...

javascript within a javascript
Hello, I have a multi-frame page. The frames are named Frame_1, Frame_2 and Frame_3. Frame_1 has a drop down box. When a value is selected in this drop down box, Frame_2 is updated using an asp file (as I have to read from a back-end access database). In turn in the asp file, I have a Body onload tag to execute a javascript function within Frame_2. this function updates the contents of Frame_3. Till now this is working fine. Here is the problem. Frame_3 has a form with a radio button. When a radio button is selected, I want that a function be executed in Frame_3. However since conte...

Expect spawn expect
Hi, I have a question about spawn an Expect script from another Expect script. $ cat foo #!/usr/bin/expect -f log_user 0 spawn "./bar" expect { eof { set s [wait] puts "[llength $s]" puts "[lindex $s 0] [lindex $s 1] [lindex $s 2] [lindex $s 3]" if { [llength $s] > 4 } { puts " [lindex $s 4] [lindex $s 5] [lindex $s 6]" exit 1 } exit 0 } } $ cat bar #!/usr/bin/expect -f If I run ./foo, sometimes I got what I expect $ ./foo 4 7868 exp6 0 0 sometimes I got what I don't expect $ ./foo 7 7880 exp6 0 0 CHILDKILLED SIGH...

dynamic load javascript from javascript
hi, from here: http://www.activewidgets.com/javascript.forum.6114.15/dynamic-load-javascript-from-javascript.html there is a method to load js from js, e.g. //--------------------------------------------------------------------------------------- var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'snip.js'; document.getElementsByTagName('head')[0].appendChild(script); //--------------------------------------------------------------------------------------- this method works great, but there is a bug(?) when using wit...

how to expect eof with expect+pty
using gnupg to encrypt a file with only a passphrase. prompt> echo 'hello world' >> test prompt> gpg -c test Enter passphrase: Repeat passphrase: prompt> note: I have not shown the many backspaces. however if there already exists a 'test.gpg' file then there is third question. prompt> echo 'hello world' >> test prompt> gpg -c test Enter passphrase: Repeat passphrase: File `test.gpg' exists. Overwrite? (y/N) I want to listen for: 'Enter passphrase: ' 'Repeat passphrase: ' eof? In case I get something else than eo...

Expect expect beginner question
Hi everybody, I am new to Expect and struggle a little bit with one of the main commands. I wrote a small script, and it doesn't work. What is wrong? script start------------------------------------------------------------------------------------------- #!/usr/bin/expect -f spawn /bin/bash .... send -- "test -d /usr\r" #does the directory /usr exist? expect "test -d /usr\r" send -- "echo $?" #make the return value visible #and here is the non working code expect { 1 { send_user "Directory doesn't exist" ...

Javascript and IE? Javascript and C#?
While my question might be simple, the environment around it is terribly messy and so I will try to keep this clear and simple by only including the relevant code - however, as I will soon suggest, I worry that the problem isnt in what would seem to be the relevant code but instead is lost somewhere in the do-and-donts of the peripheral code. So at the end, i'll try to include all the affected code and you can see if any of its actually relevant. I know there is a lot going on... sorry, but I tried to write this clearly. So here is what I imagine to be relevant. I'm working with a pa...

Question about expect, what expect() is waiting for?
Hi, I am now learning expect, and confused about the expect() call, what it is waiting for? example, .... spawn ProcessA expect ("come") send ("go") .... How "come" is sent to expect? by printf(), IPC stuff?... How ProcessA receive "go"? by scanf(), IPC stuff? Thanks for help! /K In article <1134595743.853016.32490@g44g2000cwa.googlegroups.com>, kevin <kthkevin@gmail.com> wrote: >Hi, > >I am now learning expect, and confused about the expect() call, >what it is waiting for? > >example, >... >spawn ProcessA >...

expect: Exploring expect exercise
Hi, I'm new to Expect. I'm trying to go through some exercises in Exploring Expect and am having trouble with Question 5/6 of Chapter 12 (Send): 5. Write statements to simulate the sending of the Up, Down, Left and Right arrow keys on your keyboard. 6. Solve the previous exercise in a terminal-independent way by using information from the termcap file or terminfo database. In particular, I'm having difficultly with question 6, in that I don't know how to access information from the termcap file or terminfo database in an Expect script. Can anyone provide me with some insight...

JavaScript
Javascript has it's own significance Amit Patel wrote: > Javascript has it's own significance Mr Patel, Stop using that stuff, it's bad for your brains. :P "Amit Patel" <amit2749@hotmail.com> wrote in message news:5f04ccb8.0401210427.3f93300c@posting.google.com... | Javascript has it's own significance It also has it's own group.. news:comp.lang.javascript ...

Javascript
Would anyone know whether Javascript works well with sound files? Tina Host wrote: > Would anyone know whether Javascript works well with sound files? Exactly as well as it works with files of any other type. -- |_ CJSonnack <Chris@Sonnack.com> _____________| How's my programming? | |_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL | |_____________________________________________|_______________________| ...

expect
hello, I want to write a script in using expect to connect to hosts by telnet and run a script to create a user. I arrive to connect but when I spawn my command, I am thrown out Can somebody help me? Thanks in advance GR -- grdessoub@noos.fr In article <401b58c8$0$11101$79c14f64@nan-newsreader-01.noos.net>, R�gine DESSOUBRET <grdessoub@noos.fr> wrote: >hello, > >I want to write a script in using expect to connect to hosts by telnet and >run a script to create a user. I arrive to connect but when I spawn my >command, I am thrown out >Can somebody help me? ...

JavaScript
Guys, anybody know if is possible "to press" a button linked a javascript function using python? My Firefox send something like that: POST /msgs.aspx TOKEN=B8B83BGDBC191B9FE0A0BE1393294FAB&sig=gpaiOqbp0Nr %2BoecRLF4FGGDOAao %3D&toUserId=1331299&rawAddedDate=1188546666&fromUserId=23029&Action.delete=Send +data python has modules for forms and other things... and for it? Thank you for help... zowtar >python has modules for forms and other things... and for it? Check out httplib and urlib2, it might be useful for you. Hi! I know "how to", but o...

Javascript
Recently, I have had the role of being the Javascript guru at work. You know, one peeve I have about COLA is that it seems too oriented around client applications, when the the majority of the world is about Web applications. We talk about OO -- but javascript has always been there. As has DOM, and DHTML. A web developer is a fully OO programmer. In article <5%LCb.2953$Pg1.2136@newsread1.news.pas.earthlink.net> John Bailo <ten@lnilhtrea.oliabaj> wrote: >Recently, I have had the role of being the Javascript guru at work. For single man garage business, you sure have. ...

javascript
Hi all I wounder if some one can help me i have to write a program that sums numbe3rs together using a for loop. The numbers are 1 to 10 then one to 20 then 1 to 10,000. // A program for summing numbers from one to biggestNumber Var biggestNumber; Var theSum = 0; its got to start like this. Im having problems with this one viicki -- v davies Message posted via JavaKB.com http://www.javakb.com/Uwe/Forums.aspx/java-tools/200512/1 On Fri, 16 Dec 2005 11:27:29 GMT, "vicki via JavaKB.com" <u16404@uwe> wrote, quoted or indirectly quoted someone who said : >// A program fo...

JavaScript
If I have Options/ViewingMail/AllowExecutables unchecked does Eudora strip out the JavaScript? Or just refuse to execute it? TIA... Bob "Bob Bailey" <ebiz@usa.net> wrote in message news:rfOdnaRVycZZNzXenZ2dnUVZ_v-dnZ2d@rcn.net... > If I have Options/ViewingMail/AllowExecutables unchecked does Eudora strip > out the JavaScript? Or just refuse to execute it? OK. I've answered my own question but that begs a new one. (Eudora strips the JS.) Having allowed Executables it only works if I open, not preview, the message and then it insists on ope...

javascript
Cut'n'paste from "my" ticket 202 at www.ecomstation.com as they seem to have come to a halt... :-( ################################ Recenty I went from w4 fp17 to eCS 1.2. I get the odd behavior described beneath. Both boxes sees, and uses the same installations and user profiles. Clean install(s) of both Moz and FF has been done several times. Starting FF or Moz clean (no userprofiles), doesn't make any differnce. FIREFOX: The Weather extension i.e doesn't show it's 'mouseover' info, and it refreshes slow. Unit change which ...