I have a zip code field in which there is a jQuery onKeyup event - the idea is that after they have fully entered their zip code to call the Google Maps geocoding API to immediately get the location based on that zip code.
This code works, however I would like to find a solution that ideally would not call the API several times, but wait and see if the user has finished typing using some kind of wait x time method and then calls the API.
Can anyone suggest a better way to do this?
$("#txtPostcode").keyup(function() { var postcode = $('#txtPostcode').val().length if (postcode.length >= 5 && postcode.length <= 8) { console.log('length is a valid UK length for a postcode');
source share