Skip to main content
New Participant
April 7, 2015
Answered

Link dropdown choice to autofill a second field

  • April 7, 2015
  • 5 replies
  • 45976 views

I have a dropdown field that allows me to select a variety of vendors.  Is there a way to 'link' these vendor names in the dropdown to associated contact info?  I would like to be able to select one of the vendors in the dropdown, and then have that choice trigger the autofill of a second field with contact info (address, phone, fax) related to that specific vendor.

Is this possible

This topic has been closed for replies.
Correct answer gkaiseril

Not a beginner project.

Changing Another Field with Combo Box (Drop Down) Selection by Thom Parker

5 replies

New Participant
April 29, 2022

I would like to know how to link 12345 in 1st dropdown list with Joe Bloggs in 2nd drop down list please.

 

Should they be drop down lists in the first instance or something else?

Thom Parker
Community Expert
May 17, 2022

That's too many entries for a list. And you need to explain the exact behavior that needs to happen on the form. I'd suggest creating  a new topic. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
October 26, 2020

Hi Y'all! I am using the same script as everyone else. I had it working for a while but was then asked to add another address. While the form still works, the new address does not get populated like the rest. Here's a snip of the script.

 

var DeptData = { "ALBANY":{ Address: "123 Main Avenue", Address2: "", City: "Albany, NY 12209", Phone: "518-555-5551" }, "ALBUQUERQUE":{ Address: "4200 Main Avenue NE", Address2: "", City: "Albuquerque, NM 87107", Phone: "505-555-1305"}, "ANCHORAGE":{ Address: "101 Main Avenue", Address2: "", City: "Anchorage, AK 99501", Phone: "907-555-4551" }, "HEADQUARTERS":{ Address: "935 Main NW", Address2: "", City: "Washington, DC 20535", Phone: "202-555-5505" },"ATLANTA":{ Address: "3000 Main Ave S", Address2: "", City: "Atlanta, GA 30341", Phone: "770-555-5500" }, "BALTIMORE":{ Address: "2600 Main Drive", Address2: "", City: "Baltimore, MD 21244", Phone: "410-555-5050" }, "WASHINGTON":{ Address: "601 4th Street NW", Address2: "", City: "Washington DC 20535", Phone: "202-278-2000" }};

function SetFieldValues(cDeptName)
{
// Populate fields with values from the Department Data Object
this.getField("Address").value = DeptData[cDeptName].Address;
this.getField("Address2").value = DeptData[cDeptName].Address2;
this.getField("City").value = DeptData[cDeptName].City;
this.getField("Phone").value = DeptData[cDeptName].Phone;
}

 

When I added Headquarters, the address for it does not populate when selected from the drop down menu. I basically coppied/pasted the code from ANCHORAGE and changed the info/content to what is needed. Any suggestions?

Bernd Alheit
Community Expert
October 26, 2020

Any error in the Javascript console?

Participating Frequently
October 27, 2020

I just looked at the debugger and got this.

March 31, 2020

I'm having similar issues with the same SetFieldValues function.

     - Pulldown object is "BioForm."

     - Choices are: ElfKind, Dwarf, Human, SmallFolk, HillFolk.

     - Array columns are: STR, DEX, CON, INT, WIS, CHA, Basic, Weapon, Magic, and Ultimate.

     - Form fields are same, but prefixed with "Race_".

I have gone through every combination I can imagine, and can't get over the SyntaxError: illegal character.

 
 
 

 

 

Thom Parker
Community Expert
March 31, 2020

JavaScript is very particular about syntax. All the little bits have to be set up perfectly. In a mess of code it is very difficult to just spot a small detail. So you need to tell us which line it occurs on, exactly what is on that line, and post the code in text format so it can be copied. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
April 1, 2020

Yes, Javascript IS very particular. My apologies as in my ignorance, thought I'd posed most of said information, as well as my frustration with forum posts (not y'all's fault). The Syntax Error is at the bottom left corner: illegal character...1: at line 2

Here's a simplified version (Once I get it working, I can expand the number of impacted fields, but I'm still getting the same error in the same spot):



Here's the code (If I can paste correctly):

 

var RaceData = { “ElfKind”:{ STR: "0", DEX: "1" }, “Dwarf”:{ STR: "0", DEX: "0" }, “SmallFolk”:{ STR: "0", DEX: "0" }, “Human”:{ STR: "0", DEX: "0" }, “HillFolk”:{ STR: "1", DEX: "0" }};

function SetFieldValues(BioForm)

{

    // Populate fields with values from the BioForm Object

    this.getField("Race_STR").value = RaceData[BioForm].STR;

    this.getField("Race_DEX").value = RaceData[BioForm].DEX;

}



Cap9009
Participating Frequently
August 12, 2019

Hi, I'm really new to Adobe Acrobat Pro DC, I'm versed enough to mess with Javascript and I can generally figure these things out however I have no idea where to place this code within Adobe. Can someone spell that out for me? I have two fields, my dropdown is  called STORENUM and the field I want to populate is called STOREDETAIL. What I want is for the user to select a store number and have it auto-fill the full name and address of the store associated with that number. What field options do I select and where to I place what javascript code to make this work? My current code looks like this but I can't seem to get it working as not sure where to house the data...

var DeptData = {

12:{ SNAME: "ABBOTSFORD STORE", SADDY: "32751  SOUTH FRASER WAY", SCITY: "ABBOTSFORD" },

21:{ SNAME: "CAMPBELL RIVER STORE", SADDY: "1700 TAMARAC ST", SCITY: "CAMPBELL RIVER" },

15:{ SNAME: "COQUITLAM STORE", SADDY: "110-1750 COAST MERIDIAN RD", SCITY: "PORT COQUITLAM" },

20:{ SNAME: "KAMLOOPS STORE", SADDY: "E-1420 HUGH ALLAN DRIVE", SCITY: "KAMLOOPS" }};

function SetFieldValues(cDeptName) {

    // Populate fields with values from the Department Data Object

    this.getField("DeptContact").value = DeptData[cDeptName].SNAME;

    this.getField("DeptEmail").value = DeptData[cDeptName].SADDY;

    this.getField("DeptNumber").value = DeptData[cDeptName].SCITY;

}

try67
Community Expert
August 12, 2019

You can place the code as a doc-level script (under Tools - JavaScript - Document JavaScripts, and then call it from the custom validation event of your drop-down field, like this:

SetFieldValues(event.value);

Cap9009
Participating Frequently
August 12, 2019

OK so I got the code above saved in "Document Java Script with the Script Name "SetFieldValues" i then go to the drop down properties and under Validate tab I set the custom script to  SetFieldValues(event.value); It doesn't work, do I need to put in anywhere that I want the information to populate in the STOREDETAIL text box?

gkaiserilCorrect answer
Inspiring
April 7, 2015
New Participant
April 9, 2015

Thank you.  This looks like what I had in mind.


I've studied it at home.  I'll apply it on my forms at work tomorrow and post how it works out.

On a slightly different idea, but same topic, how would I code this if I wanted to use my dropdown selection to show/hide other fields?

New Participant
April 9, 2015

GKaiseril‌ I see what you mean about not a 'beginner project.'  But after reading the code and looking at the example files, I think I will be able to adapt the script using my fields.  It won't be a walk in the park for me as a beginner...but I think I can make it happen.

Now the embarrassing question.  In the page you linked to, a 'document script dialog' page is referenced.  It mentions how to navigate to it in several versions of Acrobat.  I have Acrobat Pro 11.  Where do I find the 'advanced' tab to access the document script dialog.

I asked this next question in the above post, but I'll repeat it here.  Is there also a way to hide/show fields based on a dropdown choice?  I searched in the tutorials but wasn't able to find anything.