Solved

Using onDblClick with link

Posted on 1998-11-26
6
233 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 100 total points
Comment Utility
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
Comment Utility
But this still executes the single click operation. Can anyone do only  dblclick and not singleclick??
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

771 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

14 Experts available now in Live!

Get 1:1 Help Now