Monthly Archives: September 2015

Double-click button prevention with jQuery

Quite often it is necessary to prevent users from double-clicking on submit buttons, or in fact any buttons on your website. This is particularly important if you are processing orders or payments. Here is a very simple scriptlet which will prevent any buttons from being double clicked.

jQuery(document).ready(function(){
  jQuery("*").dblclick(function(e){
    e.preventDefault();
  });
});

The above script will prevent double clicks on all button elements. If you want to attach to a single control, such as a button called “button_submit” you can do this as follows:

jQuery(document).ready(function(){
  jQuery("#button_submit").dblclick(function(e){
    e.preventDefault();
  });
});