I have combined itechroom checkUserName function
with JohnP’s run js after user finished typing function
but it doesn’t seem to work…
$(document).ready(function(){
//JohnyP keydowntimer
var timer = null;
$('#username').keydown(function(){
clearTimeout(timer);
timer = setTimeout(checkUserName(usercheck), 1000);
});
//http://www.itechroom.com
function checkUserName(usercheck){
$('#usercheck').html('<img src="images/ajax-loader.gif" />');
$.post("checkuser.php", {username: usercheck} , function(data){
if (data != '' || data != undefined || data != null){
$('#usercheck').html(data);
}
});
}
})
I’ve tried onblur="checkUserName(this.value)" and it worked well…
It doesn’t appear that you’re declaring
usercheckanywhere (or, at least, aren’t setting its value within the snippet). What seems to be missing is…But, you also have an issue with
setTimeout. As it stands,checkUserName(usercheck)is being called immediately and the return value is then being passed tosetTimeout.Since you need to pass an argument, you can wrap the call to
checkUserNamein a new function which will be called when the timeout expires and will in turn callcheckUserName: