//show city/state on input maxlength
$("input#billZipCode").live("keyup", function( event ){
if(this.value.length == this.getAttribute('maxlength')) {
if(!$(this).data('triggered')) {
// set the 'triggered' data attribute to true
$(this).data('triggered', true);
if ($(this).valid() == true ) { zipLookup(this, "USA"); }
}
} else {
$(this).data('triggered', false);
}
});
the function zipLookup performs an ajax call and populates the fields.
The above works for when a user keys in zipcodes – however, if a user puts in a zipcode and then pastes (CTRL V) a new zipcode value, the function doesn’t fire again.
You may catch the paste event :
Reference on the
onpastecallback used by jquery : https://developer.mozilla.org/en-US/docs/DOM/element.onpasteNote that, as specified in the documentation, this doesn’t work on IE8 : you have to attach the
pasteevent directly to the element :Side notes :
on, notlive(which is deprecated)