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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

628 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