Using onDblClick with link

Posted on 1998-11-26
Last Modified: 2012-06-21
I would like to make a link perform 2 different functions.
One for single click and another for double click. When
I try it with a link, it only performs the single click function and when I move the cursor, the text on the page becomes highlighted. Any suggestions?
Question by:steve44
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1274635
I'm not sure about this for definate, but I think JavaScript only has an onClick event, not an onDblClick (as DHTML has).
The way I would suggest doing it using JavaScript is put a timeout on your function, then if the event it triggered once during the timeout interval, do this, if triggered twice during the interval, do that!

Hope this is of help!

Expert Comment

ID: 1274636
place this in the head:
<script language="JavaScript">
var clicked=null;
fucntion oneClick(){
//your click operation
fucntion oneClick(){
//your dblclick operation

and then do place this on the link you want to change
<a href="javascript:if(clicked==null)clicked=setTimeout("oneClick()",400);else{clearTimout('clicked'); twoClicks();}">whatever link description</a>

think that's about it... I might have typed wrong... but it should be right


Expert Comment

ID: 1274637
instead of using a <A HREF....> You could use a
<FORM><Input Type="button" VALUE="CLick Here" onCLick="buttonClicked();>"</FORM>
function buttonClicked(){
//your function(s)

and use the timeout thingy suggested by grdv,
or instead of the <FORM><INPUT> use an <IMG>, this will stop browsers from just following the link if they have javascript turned off.

I dunno, give it a try...

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 75

Accepted Solution

Michel Plungjan earned 100 total points
ID: 1274638
Very shabby, grdv!

steve: What you are trying is in my opinion very unintuitive and will confuse the user. If you still insist, here are two versions - the first is a working version of grdv's script - this actually works quite well.

The second is to show how it could have worked but since onClick is triggered when the user double clicks it does not. To make that work, one would need to count onMousedowns and ups.

<script language="JavaScript"><!--
function myVoid() { ; } // nothing

var clicked=null;
function oneClick(){ // oneclick operation
function twoClicks(){ // dblclick operation

<a href="javascript:myVoid()"
if(clicked==null) clicked=setTimeout('oneClick()',400);
else {
}">Click or doubleclick this</a>

<P><a href="javascript:myVoid(0)"
>onClick and on dblclick</a>

I think grdv and I both deserve points. I will answer, please accept and ask Linda in Customer services to award some points to give in a question just for grdv.


Expert Comment

ID: 9074548
But this still executes the single click operation. Can anyone do only  dblclick and not singleclick??
LVL 75

Expert Comment

by:Michel Plungjan
ID: 9101525
Please see the date.
OLD browsers.


<a href="#"
return false"
return false"
>onClick and on dblclick</a>
<P><a href="#"
return false"
>ONLY dblclick</a>

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JS to redirect to prev page 8 47
Where is this content coming from? 4 40
Change background images after 5 seconds. 12 47
Difference between Highcharts and Mapbox 10 45
In my daily work (mainly using, I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question