Skip to main content
Participant
November 21, 2017
Question

need java script help for auto populating forms

  • November 21, 2017
  • 3 replies
  • 438 views

created a shipping form with drop down box of ship to names but want to auto populate the facility name, address, phone etc based on whose name i select.. looked at alot of the info on java scripting this and just still confused,, can some one really spell it out and make it simple. i cannot load additional sofware due to system being admin locked down so have to work within adobe acrobat.. thanks

This topic has been closed for replies.

3 replies

Thom Parker
Community Expert
Community Expert
November 21, 2017

James, you have a slightly complicated request, and so the code is going to be slightly complicated and you'll need to learn a bit about scripting to make this work. The important bits are really in the fine details such as matching braces, brackets, and parentheses. Getting the location of semi colons correct, and stuff like this.  It can be a pain, So you should approach it one piece at a time.

The Article Dimitri pointed out is exactly what you need. I mean exactly. It provides the exact action you described.  Selecting an option from a drop down, which then populates a set of fields. Making the name and data changes without messing up the code syntax/formatting is the key to success.

Here's a short explanation to give you a high level view of where you are going.  There are really two separate pieces to the solution. The first piece is the data set. For each entry in the drop down there is an associated set of data for filling in the fields. In the article the data is organized as an object, where each named entry matches an entry in the drop down.  Entries that include spaces must be enclosed in Quotes. This bit messes up a lot of people. 

The second bit is the event function that selects the correct data and fills in the other fields. In the article this is written as an external function to make it more generic, but it doesn't have to be. You can put the meat of the code right into the "Keystroke" script for the field.

The only important bit is that it selects the data and writes it to the correct fields.

if(event.willCommit)

{

     this.getField("Name") = DeptData[event.value].Name;

     this.getField("Address") = DeptData[event.value].Address;

    etc...

}

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
DimitriM
Inspiring
November 21, 2017

This tutorial should be helpful-

https://acrobatusers.com/tutorials/change_another_field

Hope this helps,

Dimitri

pdfscripting.com

Participant
November 21, 2017

Thanks DimitriM,,, trying what you provided and some makes sense... changed the fieldname but still no go.. will keep working on it i don't like loosing!!

Bernd Alheit
Community Expert
Community Expert
November 21, 2017