Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using onDblClick with link

Posted on 1998-11-26
6
Medium Priority
?
252 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
[X]
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
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 400 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…

705 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