Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using onDblClick with link

Posted on 1998-11-26
6
Medium Priority
?
256 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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

971 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