In general, such a problem: I have a form, when a person presses a button quickly many times, then my requests are sent many times at once. Well, how to put a defense to display an error when it presses a lot?
3 answers
To prohibit clicking on the button you can:
1. By means of JS
2. Put on the server a timeout for accepting requests from the client
3. Check incoming data and prohibit dubbing
Plus a lot of ways. It would be cool if you described in more detail.
|
On js + jquery
like this:
$(function () { $('.once').one('submit', function () { $(this).submit(function () { return false; }); }); });
http://jsfiddle.net/oceog/P7g7m/
Without jquery
like this:
window.onload = function () { var nodelist = document.getElementsByClassName('once'); for (var i = 0; i < nodelist.length; i++) { nodelist[i].onclick = function () { this.onclick = function () { return false; } } } };
- and what exactly does she do? - phpoma
- oneintercepting submit forms, as intercepted, set a new interceptor (return false), which does not allow submitting again. You can probably for the sake of beauty also zadizeblit everything - zb
|
<!--Смысл в том, что кнопка будет работать только когда будет введена верная каптча, соответственно подряд 3-4 раза её не получится нажать--> <script> var a = Math.ceil (Math.random () * 99), b = Math.ceil (Math.random () * 9), c = a + b; document.write ( + a + ' + ' + b + ' = '); </script> <input class="input" maxlength="3" size="2" onfocus="document.getElementById ('button').disabled = 0"onblur="document.getElementById ('button').disabled = !(this.value == c)" /> <input class="button-submit" type="submit" id="button" value="ОТПРАВИТЬ" disabled="disabled"/>
|