Skip to content

Instantly share code, notes, and snippets.

@ChristopherDosin
Created June 10, 2015 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChristopherDosin/64a0eb8adaa1879b0282 to your computer and use it in GitHub Desktop.
Save ChristopherDosin/64a0eb8adaa1879b0282 to your computer and use it in GitHub Desktop.
$('#zipcode').bind('keyup change', function(e) {
if ($(this).val().length > 4) {
var ort = $('#city');
$.getJSON('http://www.geonames.org/postalCodeLookupJSON?&country=DE&callback=?', {postalcode: this.value }, function(response) {
if (response && response.postalcodes.length && response.postalcodes[0].placeName) {
ort.val(response.postalcodes[0].placeName);
}
})
} else {
$('#city').val('');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment