0

does anybody know an solution for buttons to react on 2 click events for only one button:

<input type="button" value="Click" ondblclick="alert('double')"; onclick="alert('ones')";>

@At my try if I double click on button, it alert only 'ones'; Why it isn't possible to have ondblclick and onclick in the same button?

5
  • Is it something like you want to restrict the user from double-clicking? Commented Sep 11, 2013 at 10:41
  • Then don't use alert which is modal and fired a blur event in most browsers Commented Sep 11, 2013 at 10:41
  • why do you want such behavior doesnt look good to me Commented Sep 11, 2013 at 10:42
  • If you double click the button then alert('ones') will appear on your screen.What do you wants to do ? Commented Sep 11, 2013 at 10:45
  • It is possible, but why would you want a double-click handler on a button element? It could make sense on a number of other elements (e.g., an option element within a (non drop-down) select element where one click selects and the second submits or something), but I've never needed to handle a double-click on a button. Commented Sep 11, 2013 at 10:51

2 Answers 2

6
<input type="button" value="Click" ondblclick="console.log('double');" onclick="console.log('ones')";>

Magically, it works!

Your problem is you are using alert() which is modal and so makes your ondblclick event impossible to be fired.

Sign up to request clarification or add additional context in comments.

5 Comments

+1, I think the explanation as to why the double click was not firing was what was needed.
As answered by upvote, it actually lets you doubleclick but that also fires click event twice. :)
@GaneshPandhere That's a given, seeing as double = 2
@GaneshPandhere you can still throttle click event. But i still don't know what exactly OP is looking for... Maybe expected result or not, who knows?!
even i am not sure about what is the final result expected. :)
2

You an give timeout for click so that alert pops up bit slow..

<input type="button" value="Click" ondblclick="alert('double')"; onclick="setTimeout(function(){alert('ones')},3000);";>

3 Comments

Don't use an interval at least
@GaneshPandhere now it wont
Reduce the time limit for setTimeout plss, its too much :-) hehehe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.