473,324 Members | 2,246 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,324 software developers and data experts.

Is it possible to call both events onclick,ondblclick in div tag?

Is it possible to call both events onclick,ondblclick in div tag?
Dec 2 '09 #1
3 5503
RamananKalirajan
608 512MB
This example will answer your question....

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>Cancel Click</title>
  5. <script type="text/javascript">
  6.  
  7. var iTimeoutId = null;
  8.  
  9. function startSingleClick()
  10. {
  11.   showMessage("Single click received");
  12.   iTimeoutId = setTimeout("showMessage('Single click complete')", 500);
  13. }
  14.  
  15. function startDblClick(CancelSingle)
  16. {
  17.   showMessage("Double click received");
  18.   if (CancelSingle && iTimeoutId)
  19.   {
  20.     window.clearTimeout(iTimeoutId);
  21.     showMessage("Single click cancelled");  
  22.   }
  23.   else
  24.   {
  25.     showMessage("Single click allowed");  
  26.   }
  27.   showMessage("Double click complete");
  28. }
  29.  
  30. function showMessage(Text)
  31. {
  32.   var oOutput = document.getElementById("txtOutput");
  33.   oOutput.value += (Text + "\n");
  34. }
  35.  
  36. </script>
  37. </head>
  38. <body>
  39. <div onclick="startSingleClick();" ondblclick="startDblClick(chkCancelSingle.checked);">
  40. Make Single or Double Click
  41. </div>
  42. <input type="checkbox" id="chkCancelSingle">Cancel Single Click
  43. <br>
  44. <textarea id="txtOutput" rows="20" cols="40"></textarea>
  45. </body>
  46. </html>
Thanks and Regards
Ramanan Kalirajan
Dec 2 '09 #2
chaarmann
785 Expert 512MB
From my experience it seems that the browser does not act immediately on a single click, it waits some milliseconds to see if a second click follows, so that it knows whether to call a single-click action or a double-click action. Just make a simple button and assign a small action like adding "Hello" to a text field. If you try to click it repeatedly with the mouse very fast, the text appears with a lower speed. You need to type in a special rhythm to get the fastest text-appending. Sometimes this is annoying: if I checkmark google-emails for deletion too fast, some boxes are not marked at all although I clicked on them. And some web-calculators "loose" numbers the same way.

So if you want to implement delayed action, you can just use the onClick and onDblClick, there is no problem with overlapping.
If you want to implement fast action, you should assign both onClick and onDblClick to the same action (this would solve my email problem)
And if you want to implement immediate action, use onMouseDown. (But check that mouse was up when entering the box before)
Dec 2 '09 #3
Dormilich
8,658 Expert Mod 8TB
and to get away from inline JavaScript you could also do
Expand|Select|Wrap|Line Numbers
  1. var div = document.getElementById(…);
  2. div.addEventListener("click", startSingleClick, false);
  3. div.addEventListener("dblclick", startDblClick, false); // function needs some small changes, tho
Dec 2 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Newbie | last post by:
Is it possible to set up an event handler or something else so that when *any* link on the page is clicked it 'fires-up', executes some JS and then continues to process the link that was clicked?...
2
by: Dan | last post by:
How do I catch both ondblclick and onclick on a div? /Dan *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
4
by: Amy | last post by:
I need some help. I have this table with alternate row colors. Class gray and class white. I have javascript that do highlight when mouseover row ... and onclick to select row and highlight it...
21
by: Ben | last post by:
Hello I have frames set up in an asp.net application and need one frame to refresh another. Seeing as events need to be registered at the time the page is sent from the server, I was wondering...
51
by: Paul Gorodyansky | last post by:
Hi, Ran into the following problem while trying to have a code to attach a Virtual Keyboard to any user's form: User clicks a button and my JavaScript changes outerHTML of say <textarea -...
3
by: Harry Haller | last post by:
I have a radio button group. When the page loads none of them are selected. OnClick selects ONE and clicking another one selects a different one - this is normal behavior. I want to modify it so...
12
by: Andrew C | last post by:
Hi, folks. I've recently been doing a few simple tests and experiments. As a result, I've noticed that, in dealing with 'onclick', IE seems less able than Firefox to keep up with rapid clicking....
1
by: stephen.cunliffe | last post by:
Situation: I have a few event handlers (not onclick) on a text box. The handlers take in an event parameter to work some magic. All the above works fine, but I have a desire/need, to "invoke"...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.