I have an ajax call triggering on the maxlength of an input. However, it continues to trigger if a user continues to enter characters (because they count as a keypress). Is there any way to prevent additional ajax calls after the 5 character limit?
html
<input type="text" value="" id="billZipCode" name="billZipCode" class="smallInput coreAddrBill" maxlength="5">
javascript
//show city/state on input maxlength
$("input#billZipCode").live("keyup", function( event ){
if(this.value.length == this.getAttribute('maxlength')) {
if ($(this).valid() == true ) {
zipLookup(this, "USA");
}
}
});
Set a
.dataattribute on the field:Move the assignment inside the second
ifstatement if you want to keep running this until the zipcode is valid.