Question : Ajax response skipping (Validation fields)

I'm fairly new to the world of Ajax and Java Scripting

I have created a textbox validation using ajax (runs a PHP file which checks and responds)

Everything seems to run fine but I've noticed that if the user types fast enough, validation is not fully checked or is skipped. Try it here: http://stipe.com.au/moopanel/?page=register.php
Example: Username character size must be greater than 5.
Type fast, enter 6 letters, and then tab out.  The error message will still be stuck on "User Name is too short!" when it should really say OK

Anyone experienced this problem before?
My javascript executes on keypress or on blur. Feel free to view the source of my code from that link. If you need further code let me know.

Answer : Ajax response skipping (Validation fields)

In this case, the correct way is to run forever a function every 500ms, which checks if the content of the text input has changed. If so, it makes the call.

For example :
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var lastvalue = null;
 
function checkInput() {
 var value = document.getElementById('yourTextInput').value;
 if (value != lastvalue) {
  runAjax();
  lastvalue = value;
 }
 setTimeout(checkInput, 500);
}
 
window.onload = checkInput;
Open in New Window Select All
Random Solutions  
 
programming4us programming4us