For Getting city, state and country using zip code:
Reference URL : http://www.zippopotam.us/
GitHub reference : https://github.com/crowell/Zippopotamus
$('input[title="ZipCode Required Field"]').blur(function(){
var zip = $(this).val();
var city = '';
var state = '';
//make a request to the google geocode api
$.getJSON({
url : 'https://api.zippopotam.us/us/'+zip+'',
data : {
sensor : false
},
success : function( data, textStatus ) {
debugger;
state =data.places[0].state;
city =data.places["0"]["place name"];
country =data.country;
//pre-fill the city and state
$('input[title="City"]').val(city);
$('input[title="State Required Field"]').val(state);
$('input[title="Country Required Field"]').val(country);
}
});
});
Reference URL : http://www.zippopotam.us/
GitHub reference : https://github.com/crowell/Zippopotamus
$('input[title="ZipCode Required Field"]').blur(function(){
var zip = $(this).val();
var city = '';
var state = '';
//make a request to the google geocode api
$.getJSON({
url : 'https://api.zippopotam.us/us/'+zip+'',
data : {
sensor : false
},
success : function( data, textStatus ) {
debugger;
state =data.places[0].state;
city =data.places["0"]["place name"];
country =data.country;
//pre-fill the city and state
$('input[title="City"]').val(city);
$('input[title="State Required Field"]').val(state);
$('input[title="Country Required Field"]').val(country);
}
});
});
No comments:
Post a Comment