473,382 Members | 1,355 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,382 software developers and data experts.

Click event and Double Click event on a single button

1
Hello Friends,
I want to trigger both the click event and double click event in a single button separately. (i.e.) the user can trigger both the single click and the double click event. if they click once, it should trigger single click event. if they click twice, it should trigger double click event.

please Help.


Cumars
Oct 11 '06 #1
2 9477
acoder
16,027 Expert Mod 8TB
Add both onclick and ondblclick event handlers to the button object, e.g.
[html]<input type="button" onclick="alert('you only clicked once');" ondblclick="alert('you double clicked');" value="Single or Double Click">[/html]
May 22 '08 #2
mrhoo
428 256MB
You can avoid the single click handler when you doubleclick,
but it requires setting a timeout for the single click handler,
and cancelling it if a doubleclick is called on.

Expand|Select|Wrap|Line Numbers
  1. function oneclickevent(e){
  2.     e= window.event || e;
  3.     var who= e.srcElement || e.target;
  4.     var s= who.id || who.tagName;
  5.     s+='\n'+e.type;
  6.     if(!window.clicktimer) window.clicktimer= setTimeout(function(){
  7.         alert(s);
  8.         window.clicktimer= undefined;
  9.     },
  10.     500);
  11. }
  12. function twoclickevent(e){
  13.     clearTimeout(clicktimer);
  14.     e= window.event || e;
  15.     var who= e.srcElement || e.target;
  16.     var s= who.id || who.tagName;
  17.     alert(s+'\n'+e.type);
  18.     window.clicktimer= undefined;
  19. }

var el= document.getElementById('mybutton');
el.onclick= oneclickevent;
el.ondblclick= twoclickevent;


The delay for the single click may be a pain,and difficult to set for all users.
And some people will click multiple times which can send a single click after the double click returns-
Besides, it is tough to implement for keyboard access-
consider making your second event a click+shiftkey,
and handle it without a delay either way.
May 22 '08 #3

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

Similar topics

0
by: balg | last post by:
I have an outer control + inner control; I need to capture click + dblclick on outer control; but on click, i focus on the inner control which is directly under the mouse; so dblclick on outer...
3
by: Angela Chen | last post by:
Hi, I have a readOnly textbox. I want to be able to double click it to make it editable? How to implement it?\ Thanks a lot
3
by: Siv | last post by:
Hi, I have a ListView control in a Windows application, currently single clicking a customer name in this list, selects the customer and displays their details in text boxes to the right of the...
0
by: praveenkumar.117 | last post by:
Dear all, I am developing an GUI application using Tix I want to trigger a window on single or double click on a name displayed in the GUI. How to go about using Python your help is very much...
5
by: sethuganesh | last post by:
hi, i have created a sample window aplication in VB.NET.placed a listview component in the form ,written click and double click event for list view.But the events are not fired.is there any...
3
by: Techsatish | last post by:
how to make a mouseup event called only once during a double click event? here double click is made on a tree node in a tree control. I have the code inside mouseup event....in runtime the...
1
by: dayanand | last post by:
Hi all i have created a page where i want to doubleclick a name which should go to edit profile page and the same way single click to go to confirmation whther to go to edit profile or not.. ...
1
by: JT | last post by:
Hi, I want to disable the ability to launch an application that is embedded in the text of a RichTextBox control. I've seen various posts that say that doing the following will disable click...
4
by: vineetbindal | last post by:
Hi all, I have a gridview, when onselectedindexchanged in fired. i want to convert the selected row's column's into dropdown so that user can select the new value and update it. please tell me...
2
by: wizi | last post by:
Hi everyone, I am writing an application that allows users change Left Click to Right and Double Click. For example: if an user hit the "Double Click" button, Left click = Double Click. For...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.