You better use input
instead of keyup
, because the keyup
will pick up any keystroke, even TAB, SHIFT or other. The input
will call the function only when something is typed in the field.
You can do it this way:
var temporiza;
$("#email").on("input", function(){
clearTimeout(temporiza);
temporiza = setTimeout(function(){
alert("Chama Ajax");
}, 3000);
});
var temporiza;
$("#email").on("input", function(){
clearTimeout(temporiza);
temporiza = setTimeout(function(){
alert("Chama Ajax");
}, 3000);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="email" id="email" placeholder="Digite o e-mail" />
I saw a problem kind of silly however it is essential for a good functioning, the timer must reset every time the key is pressed it seems to me that this way will not work like this
– Estudante PHP
@Estudtephp Works this way: every time a character is inserted in the field, the timer Zera. If you think it best to put
keyup
, works also, will pick any key pressed.– Sam
worked perfectly here thanks :)
– Estudante PHP