Skip to content

Instantly share code, notes, and snippets.

@schmidt1024
Created February 9, 2015 10:16
Show Gist options
  • Save schmidt1024/e69dba7c7371947450df to your computer and use it in GitHub Desktop.
Save schmidt1024/e69dba7c7371947450df to your computer and use it in GitHub Desktop.
autocomplete city based on zip code / Autovervollständigung Ort bzw. Stadt anhand Postleitzahl
$('#zip').blur(function() {
var city = $('#city');
if (!city.val()) {
$.getJSON('http://www.geonames.org/postalCodeLookupJSON?&country=DE&callback=?', {postalcode: this.value }, function(response) {
if (!city.val() && response && response.postalcodes.length && response.postalcodes[0].placeName) {
city.val(response.postalcodes[0].placeName);
}
})
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment