Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.