Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Autopopulate State and Zipcode when typing in Town.

New Here ,
Feb 09, 2017 Feb 09, 2017

Hi There,

I'm creating a form for work - and am not very tech savvy.  I programmed my form to use checkboxes (after searching forums for hours) WOOP. I can not seem to , however, figure out how to have my text fields auto populate.  I would like my clients to type in their town or city and have the state and zipcode auto populate.  We are working with a specific state so I don't need to pull from a huge database, was hoping to manually enter all info (annoying, but I have time) for adobe to pull from.

Would anyone be able to explain to me how to do this, and possibly provide the script as well. This is probably a fairly easy thing, I just can not figure it out. I've tried to manipulate other scripts but I don't think I truly understand how it works.

Thanks!

A

TOPICS
Acrobat SDK and JavaScript , Windows
631
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 09, 2017 Feb 09, 2017

There are a couple of ways of doing it. The smart way (but more complicated) and the hard way (which is easier to implement, but requires much more work). The smart way is to create a spreadsheet with the town names in the first column, the zip code in the second and the state in the third and then attach that spreadsheet to the PDF file and use a script to look up the zip code and states whenever a town name is entered. It could even be possible to use a drop-down field for the town names and populate it based on the state selection (again, using a drop-down), and then the zip code based on the town name. This requires quite a complicated, custom-made script, though, but it has the advantage of being much more flexible and easier to maintain than the alternative.

The alternative, hard way, is to hard-code everything into the validation script of the text field. The basic structure would be:

if (event.value == "New York") {

    this.getField("State").value = "NY";

    this.getField("Zip").value = "10001";
} else if (event.value == "Albany") {

    this.getField("State").value = "NY";

    this.getField("Zip").value = "12084";

} // etc

else {

    this.getField("State").value = "";

    this.getField("Zip").value = "";

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 09, 2017 Feb 09, 2017

Thank you so much. Out of curiosity and if you have time, would you be willing to walk me through the more complicated but smarter way?  I have all of the information in a spreadsheet already (i tried to do this form in excel first... yikes).  If not, which I would completely understand, I will start doing this the easier but not as efficient way!

Thank you again, can't tell you how much this helps!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 09, 2017 Feb 09, 2017

If you want to discuss it in detail, including the option of me developing

this code for you for a fee, you can contact me privately at try6767 at

gmail.com .

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 10, 2017 Feb 10, 2017

You should be aware that a 5 digit U.S. Zip codes can be used by more than on municipality and may cover more than one town.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 16, 2017 Feb 16, 2017
LATEST

I can not seem to get this script to work... I'm entering it as javascript . argh, I am very adobe illiterate. And thanks for the heads up on ZIp Codes being used by more than one municipality and covering more than one town, the form is mainly for records keeping so we are using the "main" zip code per town only assigning one per town etc.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines