Reputation: 1244
I have the following if statement in a jquery function triggered by onKeyUp
in a text input field
if ( famcount < 3 ) {
alert('number too small.');
} else if ( famcount > 10 ){
alert('number too large.');
}
The problem is, if the user tries to type 10
it executes after the 1 and triggers the first alert. Any suggestions on a better way to trigger this event than onKeyUp
?
Upvotes: 1
Views: 95
Reputation: 13948
you could use the .blur()
event.
Because even if the user is trying to enter 5 digits the keyup event is supposed to fire 5 times so that's normal.
Or you could bind the validation to on user submit.
Upvotes: 2