How do I populate a text field based on a selection in a drop down field?

Community Beginner ,
Dec 10, 2018 Dec 10, 2018

Copy link to clipboard

Copied

Field 1 is Acct #

Field 2 Sold To (this is the clients name based on the account # selected in field 1)

Filed 2 Ship To (this is the clients address based on the account # selected in field 1)

It is my understanding that I shoud run a javascript. However, I am VERY new to this and am unsure of how/what code to write.

TOPICS
Acrobat SDK and JavaScript

Views

121

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Dec 11, 2018 Dec 11, 2018

Copy link to clipboard

Copied

Since there are 3 fields to populate from a single dropdown selection, the field data will need to be stored in an object. 

Like this: (this code can be placed in a document level script)

var aFldData = {"AA":{Acct:"acount AA number", "SoldTo":"AA sold to", "ShipTo":"AA Ship To"},

                              "BB":{Acct:"acount BB number", "SoldTo":"BB sold to", "ShipTo":"BB Ship To"},

                              .... etc ...

                         }

"AA" and "BB" are the entries in the dropdown. Use this code in the Custom Keystroke event for the dropdown

if(!event.willCommit)

{

    this.getFeild("Field1").value = aFldData[event.change].Acct;

    this.getFeild("Field2Sold").value = aFldData[event.change].SoldTo;

    this.getFeild("Field2Ship").value = aFldData[event.change].ShipTo;

}

You'll need to change the field names so the ones on your form match the ones in the script.

You can learn more about lists here:

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

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 Beginner ,
Dec 11, 2018 Dec 11, 2018

Copy link to clipboard

Copied

Thom,

Thank you for you assistance! LIke I said I am very new to this code business and want to make sure I understand what I am doing. So, of course there are a few questions...

What do you mean by "placed in a document level script? (I am working in Acrobat pro DC.) Does this mean I go to the properties of each field I would like to populated and enter this code where I can add the javascript?

When I originally built the form in excel, I put the same formula in both the "sold to" and "ship to" fields. Each formula read what was in Acct # field and then populated the data that correlated with the accout number. 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Dec 11, 2018 Dec 11, 2018

Copy link to clipboard

Copied

You could place separate code in each text field. There are always options for different implementations. When I create a solution I like to keep everything in one place, so it can be managed from one place.

The data does not need to be in a document level script, it can be placed in the same script as the code. This is just a preference.

The code I provided is designed specifically for the Custom keystroke event on the dropdown list. You'll find this event script on the "Format" Tab of the properties dialog for the dropdown.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

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 Beginner ,
Dec 13, 2018 Dec 13, 2018

Copy link to clipboard

Copied

Ok, I am have finally gotten time to try this and it isn't working and I guess I am confused.

I clicked on the drop down and went into the drop down properies. I went to the screen you showed above and entered the code you gave me. I changed the field name and added an acct number, business name, and address. Then I get a syntex error. (It only highlights the 3rd line but when I snipped it, it did them all.)

Also, I have 75 - 100 account numbers that will have business names and addresses to enter. How do I add all of them?

To be honest the first code that you gave makes more sense to me, I just know NOTHING about what you mean by placing it in document level script.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Dec 14, 2018 Dec 14, 2018

Copy link to clipboard

Copied

The problem is with things like this:

aFldData[event.change].City Market

You can't have spaces in the names of the variables, or you have put them in quotes, like this:

aFldData[event.change]["City Market"]

Or:

aFldData[event.change].CityMarket

Anyway, if you have a large set of data then typing it all out in this way is honestly a waste of time and energy.

It's possible to attach the full spreadsheet into the PDF and then read the data directly from it using a script, and use that data to populate the fields when a selection is made in the main drop-down field. I've actually developed a (paid-for) tool that allows you to do just that very easily, without having to write any code. You can find it here: Custom-made Adobe Scripts: Acrobat -- Populate Fields From Dropdown

Likes

Translate

Translate

Report

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 Beginner ,
Dec 14, 2018 Dec 14, 2018

Copy link to clipboard

Copied

I have purchased the tool and have downloaded it. Now I don't see the tool add on, so that I can proceed.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Dec 14, 2018 Dec 14, 2018

Copy link to clipboard

Copied

Before you proceed with the external tool. It's worth it to fix the issue you have now so you know how it is supposed to work.

Can you post the code that defines "aFldData". I suspect it needs some fixup.

Also, there are articles on the posted website that show exactly how to do this:

https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Dec 14, 2018 Dec 14, 2018

Copy link to clipboard

Copied

LATEST

It's probably not installed correctly. Please contact me by email (try6767 at gmail.com) and I'll help you sort it out.

Likes

Translate

Translate

Report

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