Hi i have a zipcode field when user enters a 5/9 digit zip it should auto populate the State and city fields.
Is there any thing like this usin javascript or JQuery???
Thanks
Select the cell or range of cells that you want to format. , click the arrow, and then click More Number Formats. In the Format Cells dialog box, under Category, click Special. In the Type list, click Zip Code or Zip Code + 4.
ZIP is an acronym for Zone Improvement Plan. However, the USPS intentionally chose the acronym to indicate that mail travels more quickly when senders mark the postal code on their packages and envelopes.
ZIP codes can and do cross state lines (rarely, but just enough to cause some problems and confusion), county lines (about 10% of ZIPs are in more than one county), political jurisdictions (cities, congressional districts), metro areas, etc.
Using the Javascript Google Maps V3 API:
You need to reference this:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
Do this:=
var zip = <yourzipcode>;
var lat;
var lng;
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': zip }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
geocoder.geocode({'latLng': results[0].geometry.location}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
var loc = getCityState(results);
}
}
});
}
});
function getCityState(results)
{
var a = results[0].address_components;
var city, state;
for(i = 0; i < a.length; ++i)
{
var t = a[i].types;
if(compIsType(t, 'administrative_area_level_1'))
state = a[i].long_name; //store the state
else if(compIsType(t, 'locality'))
city = a[i].long_name; //store the city
}
return (city + ', ' + state)
}
function compIsType(t, s) {
for(z = 0; z < t.length; ++z)
if(t[z] == s)
return true;
return false;
}
This all returns a string containing the city and state in this format , but you can adjust this to your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With