Reputation: 1237
I have this code, basically I have <input id="register_username" type="text" name="username">
and I want to check if the users already exist in the database or not. The code works perfectly when the user type a username, but sometimes some browsers (for example Firefox) gives the user drop down menu and let them choose some values they already entered in the past (such as their name). The problem is when the chose the username from the drop down menu, the keyup
function does not work. How can I fix this problem ?
$("#register_username").live('keyup', function() {
$.post('scripts/register/register_check.php', {
checkusername: $('#register_username').val()
}, function(data) {
if (data == "good") {
//do something
} else {
//do the other thing
}
});
});
Upvotes: 0
Views: 442
Reputation: 5399
I would use the onblur event to fire whenever the field loses focus.
Upvotes: 0
Reputation: 23537
I don't think all browers if any triggers an event after choosing an option from an autocomplete dropdown.
Your best bet is to use .change()
which will trigger after the element loses focus. For example, when the user chooses an autocomplete option and move on to the next field.
Upvotes: 1