My main question is: Does clearTimeout() stop the timer AND not execute the function within the timer? OR does it just clear the timeout and immediately execute the function?
Here's my example
$('input').keyup(function(){
var thisClass = $(this).attr('class').split(" ");
var thisValue = $(this).val();
var thisError = $(this).parent().siblings('.error');
var thisTimeout;
if(thisClass[1] == "letters"){
if(thisValue.length <= 1){
thisTimeout = setTimeout(function(){
thisError.html("You must have at least 2 characters");
thisError.show();
}, 800);
} else {
clearTimeout(thisTimeout);
thisError.hide();
thisError.html("");
}
}
});
This is part of a code checks to see if an input box has at least 2 characters in it. currently, This code executes the timeout well after 800 miliseconds if it has 2 or less characters. When the input box has more than 2 characters, if I'm typing fast enough, the error box still shows up when I finish typing. I can clear the error by typing one more character, but if I were to type my name quickly, The error shows up when I'm done typing.
I also have this piece of code:
$('input').keydown(function(){
clearTimeout(thisTimeout);
thisError.hide();
});
Hoping that it would clear the error if I kept typing Thoughts?