I'm trying to distinguish between an onclick event and an ondblclick event on the same HTML element...since the onclick event always fires first before the ondblclick event can fire, I'm trying to create a workaround as follows:

The problem I'm having here is that alert(lastClickTime); is always evaluating to be the same number, and thus the "ondblclick" code is never executed beyond the first second of the first divObj.onclick event firing...

Thanks for any help.

glenngv

02-22-2007, 10:20 PM

Try using getMilliseconds() instead of getTime() and change 1000 delay to something appropriate. But I think that would still not be 100% accurate. I think the more accurate solution would be to delay the click function a bit by using setTimeout and in the dblclick function, cancel the setTimeout.

divObj.ondblclick = function()
{
clearTimeout(timer);
dispObj.innerHTML += 'ondblclick';
x = 0;
}
</script>
Also, I increased the delay from 200 to 300 to make room for the default double-click speed setting in the Mouse Properties in Control Panel. This will at least minimize the onclick to be fired on ondblclick. If you use 200, the onclick still fires if you double-click slowly within the set speed. Of course, this code will not work perfectly all the time if speed is set to a very Slow setting. This is usually set for inexperienced mouse users. If we could only programmatically determine the speed setting then there would be a perfect solution to this.

/*********************************************
* Delays click events for about 0,6 seconds - if a second click is performed
* during this periode, the click event will not be executed at all -> only the
* ondblclick event will be executed.
* returns true if the further functions of the element.onclick/element.ondblclick shell
* be executed or false to prevent the execution.
*/
delay: function(event) {
var elem = Element.extend((event.target) ? event.target : event.srcElement);
var dispatcher=this;