javascript - Adding a timed delay after pressing a button to prevent button spam -


say have 4 buttons

    <button id="one">one</button>     <button id="two">two</button>     <button id="three">three</button>     <button id="four">four</button> 

and prevent spam, want make whenever of buttons pressed, none of them able pressed again next 0.6 seconds.

how might achieve this?

you can use javascript code:

var btns = document.getelementsbytagname('button'); for(var i=0;i<btns.length;i++){     btns[i].addeventlistener('click', function(){         disablebuttons(true);         settimeout(function(){disablebuttons(false);}, 600);     });     } function disablebuttons(state){     for(var i=0;i<btns.length;i++){         btns[i].disabled = !!state;         } } 

of course, need run code after page loaded.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -