Copy link to clipboard
Copied
Hi.
So I'm working on a form for my job, and my superior has asked me to find a way to generate the right city and the right postal code based on an address. So I've heard that Google Maps offer this kind of auto-complete option, but it's not free (we're a small business). Is there a free way to do it, maybe with JavaScript ?
Thank you.
Copy link to clipboard
Copied
You can use this as 'Validation' script of "Address" field:
var city = this.getField("City");
var postal = this.getField("Postal code");
if(event.value == "Address1"){
city.value = "City1";
postal.value = "Postal code1";}
else if(event.value == "Address2"){
city.value = "City2";
postal.value = "Postal code2";}
else if(event.value == "Address3"){
city.value = "City3";
postal.value = "Postal code3";}
//add more 'else if' if needed
else{
city.value = "";
postal.value = "";}
Just change field names to your actual field names.
Copy link to clipboard
Copied
You need to use or (||) for multiple strings, like this:
if (event.value === "Walmart Inc." || event.value === "Walmart" || event.value === "walmart")
Copy link to clipboard
Copied
Are you talking about JS in a PDF file, or in a web-page? Because this forum is about the former.
Copy link to clipboard
Copied
In a PDF file
Copy link to clipboard
Copied
In that case then no, unless you embed the entire address DB into your file...
Copy link to clipboard
Copied
How would that be possible ?
Copy link to clipboard
Copied
I only need a small number of adresses, and I have them all in a document.
Copy link to clipboard
Copied
You can use this as 'Validation' script of "Address" field:
var city = this.getField("City");
var postal = this.getField("Postal code");
if(event.value == "Address1"){
city.value = "City1";
postal.value = "Postal code1";}
else if(event.value == "Address2"){
city.value = "City2";
postal.value = "Postal code2";}
else if(event.value == "Address3"){
city.value = "City3";
postal.value = "Postal code3";}
//add more 'else if' if needed
else{
city.value = "";
postal.value = "";}
Just change field names to your actual field names.
Copy link to clipboard
Copied
Thank you.
Copy link to clipboard
Copied
Hi, I have a little problem with the code. When I write the subsequent adresses with "else if", it completes the city and postal code field with the correspondant answer of the first adress. When I only write "If" for every adresses, it automatically fill the correspondant city and postal code fields with the last adress data. How to solve this problem ?
Copy link to clipboard
Copied
Post the script you tried or the actual file (with script inside).
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You need to use or (||) for multiple strings, like this:
if (event.value === "Walmart Inc." || event.value === "Walmart" || event.value === "walmart")
Find more inspiration, events, and resources on the new Adobe Community
Explore Now