I have one text box and i am entering data on that text box, what i want to do is: if i will enter 4 characters and will skip that text box by pressing TAB key then one alert will come as"data should be more than 4 characters" and then text box will be auto refreshed. If data entered is more than 4 characters then no alert will come, I was trying by onkeyup event but some where i am doing wrong. Any help please
I have one text box and i am entering data on that text box
Share
I don’t know what you mean by “then text box will be auto refreshed”, so I’m going to guess that you want to put the cursor back into that field. As far as checking the length of the value when tabbing out you want the
.change()or.blur()event:Demo: http://jsfiddle.net/XHKRh/
The blur event will be triggered every time the focus leaves the field; the change event will not be triggered again if the user immediately tabs out of the field again without changing it. I prefer to use change in combination with an additional validation on form submit, so that the user doesn’t keep getting pestered with alerts (though actually I wouldn’t show an alert at all, I’d put the message on the page next to the field).