The timeout is being cleared. The problem is that you are calling your function immediately instead of passing the function to setTimeout
.
setTimeout(isUsernameAvailable($(this).val()), 1000);
isUsernameAvailable($(this).val())
will be called and the result of this call will be passed to setTimeout
.
You should instead pass a function which calls this function:
EDIT: As @Mark said, you also need to deal with this
not being what you expect:
var value = $(this).val();
setTimeout(function(){
isUsernameAvailable(value)
}, 1000);