I’ve a form field with one input field.
As soon as the user completes typing i need to make an ajax call and validate input on serverside.
I tired keyup, focusout, keydown and mouseup events but doesn’t seem to work as expected. Could some one please suggest the best keyboard events to choose to resolve this. If the input is blank the error message should be shown as well.
The event you are probably looking for is the blur() event, which is called when the user
leaves an input field (by pressing tab, or clicking on the next input for example)
Example:
EDIT:
Validating via AJAX is VERY bad practice, as one could easily stop the HTTP request or disable JavaScript entirely (and personally I try to avoid unnecessary http requests).
I recommend first checking client side (JavaScript/jQuery only), and when submitted double check server-side (with PHP/ASP).