The easist way to avoid double clicks in submit buttons

Most of the sites have this problem, for example, when user want to create an account. The fill in the registration from, and submit the form. If the site is too slow at that moment. they would click again, and you have double entries.

With this JavaScript class, you deactivate this. Just put that and end of your site.

function ClickObServer(){
   this.deactivateDoubleClicks = function() {
       this.checkClicks(document.getElementsByTagName("a"));
       this.checkClicks(document.getElementsByTagName("input"));
   }
   this.checkClicks = function ( el ){
       for (var i = 0; i < el.length; i++) {
           if( el[i].onclick == null ){
                el[i].onclick = this.myClick;
           }
       }
   }
   this.myClick = function (){
        if( this.clicked == true ){
           return false;
       }
       this.clicked = true;
       return true;
    }
}
co = new ClickObServer();
co.deactivateDoubleClicks();

add new comment | read more

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.