Solved

Using onDblClick with link

Posted on 1998-11-26
6
237 Views
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?
0
Comment
Question by:steve44
6 Comments
 

Expert Comment

by:burtons2
ID: 1274635
Hi,
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!
0
 
LVL 2

Expert Comment

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

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

//grdv
0
 

Expert Comment

by:th_c_man
ID: 1274637
instead of using a <A HREF....> You could use a
<FORM><Input Type="button" VALUE="CLick Here" onCLick="buttonClicked();>"</FORM>
<SCRIPT>
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...

Daniel
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 75

Accepted Solution

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

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

var clicked=null;
function oneClick(){ // oneclick operation
   alert('one');
   clicked=null;
}
function twoClicks(){ // dblclick operation
   alert('two');
   clicked=null;
}
//--></script>

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

<P><a href="javascript:myVoid(0)"
onClick="document.forms[0].elements[0].value='one'"
onDblClick="document.forms[0].elements[1].value='two'"
>onClick and on dblclick</a>
<FORM>
<INPUT TYPE="TEXT">
<INPUT TYPE="TEXT">
</FORM>
</HTML>

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.

Michel
0
 
LVL 1

Expert Comment

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

Expert Comment

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

Here

<a href="#"
onClick="document.forms[0].elements[0].value='one';
return false"
onDblClick="document.forms[0].elements[1].value='two';
return false"
>onClick and on dblclick</a>
<P><a href="#"
onDblClick="document.forms[0].elements[1].value='two';
return false"
>ONLY dblclick</a>
<FORM>
<INPUT TYPE="TEXT">
<INPUT TYPE="TEXT">
</FORM>
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Facebook React and SyntheticEvents 6 48
jQuery Syntax 2 47
How to make interactive HTML code pages like w3school or Codecademy? 3 29
is this a cms? 8 34
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now