File: /home/healthvaluequotes/public_html/backup2/lp2/js/zipCodeLookup.js
function zipCodeLookup(id) {
var city, state, zip;
if(id == '1')
{
zip = $('#zipCode').val();
}
if(id == '2')
{
zip = $('#zipCode2').val();
}
var clientKey = "AIzaSyCAq_c3m1vTOYIu3FwmKJyFjELkkueBVow";
if (zip.length === 5) {
$.ajax({
type:"GET",
url:`https://maps.googleapis.com/maps/api/geocode/json?address=${zip}&key=${clientKey}`,
}).done(function(response)
{
console.log(response);
var address_components = response.results[0].address_components;
$.each(address_components, function(index, component){
var types = component.types;
$.each(types, function(index, type){
if(type == 'locality') {
city = component.long_name;
$('.city').val(city);
}
if(type == 'administrative_area_level_1') {
state = component.short_name;
$('.state').val(state);
$('.displayLocation').text(`In ${$('#city').val()}, ${$('#state').val()}`);
$('.displayLocation2').text(`In ${$('#city').val()}, ${$('#state').val()}`);
}
});
});
});
}
};