This is a notification for Guests
Forums / General Questions / Autofill City & State from Zip Code

Autofill City & State from Zip Code

Results 1 to 5 of 5
11 Feb 2020, 19:46
#1
chadlly2003 avatar

chadlly2003

Totally Zenned

Join Date:
Jan 2015
Posts:
723
Plugin Contributions:
0

Autofill City & State from Zip Code

does anyone know if there is a plugin or module that can help me Autofill City & State from Zip Code .

Baiscally when a customer puts his zip code i want the city and state to auto populate.

If someone could assist me or lead me in the right direction i would appreciate it
11 Feb 2020, 21:40
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Posts:
13,980
Plugin Contributions:
46

Re: Autofill City & State from Zip Code

chadlly2003:

does anyone know if there is a plugin or module that can help me Autofill City & State from Zip Code .

Baiscally when a customer puts his zip code i want the city and state to auto populate.

If someone could assist me or lead me in the right direction i would appreciate it

I've been using this Zip Codes to Location service (https://www.zipcodeapi.com/index.php) for a couple of years now; works the treat!
11 Feb 2020, 21:55
#3
chadlly2003 avatar

chadlly2003

Totally Zenned

Join Date:
Jan 2015
Posts:
723
Plugin Contributions:
0

Re: Autofill City & State from Zip Code

Lat9,

Do you have an example of implementation. I am not really sure how to go about getting this to work with zencart
12 Feb 2020, 02:38
#4
carlwhat avatar

carlwhat

Totally Zenned

Join Date:
Nov 2005
Posts:
2,932
Plugin Contributions:
5

Re: Autofill City & State from Zip Code

interesting API... like it... i think...

does not seem that tricky to implement, with the exception of the "...has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."

is.gd/fNujQC

i think it totally makes sense to enter zip codes first and then autofill city state codes...

securely addressing the above error will be the tricky part...

@chadlly2003, the way to implement this is to register for an application key, copy the the javascript code from here:

https://www.zipcodeapi.com/API#example1

and then place that on the page where you have your address... you then need to change the key in the js code to your key, find this code:

//from:
container.find("input[name='zipcode']").on("keyup change", function() {
//to:
container.find("input[name='postcode']").on("keyup change", function() {


you will then need to find the container that the postcode is in on your page, and change the following 2 elements:

		var container = $("#example1");
		var errorDiv = container.find("div.text-error");
is.gd/fNujQC


those 2 elements will be dependent on your template.

hope that gives you enough to go on.... not super easy but again not super hard. the error i'm experiencing above will be tickier to solve. you should be able to see that in the developer tools console of your browser.

good luck.
12 Feb 2020, 05:48
#5
chadlly2003 avatar

chadlly2003

Totally Zenned

Join Date:
Jan 2015
Posts:
723
Plugin Contributions:
0

Re: Autofill City & State from Zip Code

Actually I figured it out. Was a lot easier than I thought. Working perfectly on my site:)