Simulate double click for asp.net button in javascript

1.2k views Asked by At

I have a asp.net button called update. I have to carry some test when the button is double clicked. But as of now, sometime it recognizes the double click and sometimes it doesnt. So i need to simulate double click when i click once.

1

There are 1 answers

0
Shadow Wizard Love Zelda On

Double click for button is pretty much meaningless as each click will trigger it's onclick event.

Safest way is build your own "double click" event using the ordinary onclick.. required JS:

function ClickMe(oButton) {
    if (oButton.getAttribute("clicked") == "1") {
        alert("double click!");
        oButton.setAttribute("clicked", "0");
        return;
    }

    oButton.setAttribute("clicked", "1");
    window.setTimeout(function() { oButton.setAttribute("clicked", "0"); }, 500);
}

And the HTML:

<button type="button" onclick="ClickMe(this);">Click</button>

Test case: http://jsfiddle.net/yahavbr/HGJEG/