This is an idea as your code is working. Do it this way. First check your textfield if it is more than 10 character or not. call fnc() onkeyup
function fnc()
{
length=document.getElementById("atext").value.length;
if(length==10)
{
callyourajaxfunction()
}
}