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

Looking to autofill a text field with information, depending on what is chosen in a drop down field

New Here ,
Mar 07, 2023 Mar 07, 2023

Hello,

 

I have looked in the community and found similar questions and answers, and have tried some of the suggested scripts, but have not have any luck making any work yet.

I'm using Adobe Creative Cloud v 5.10.0.573

Tool: Acrobat Prepare Form on a Mac: OS Monterey v 12.4

 

I have a drop down menu in a field that has several options of people's names to choose from.

I'd like a text field to autofill with an address, based on which name is selected (each address is different, based on which name is selected).

 

I am not too familiar with javascript but am totally ok with learning.

 

Any help is greatly appreciated!

 

 

 

TOPICS
Edit and convert PDFs , How to , JavaScript , PDF forms
961
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
1 ACCEPTED SOLUTION
Community Expert ,
Mar 07, 2023 Mar 07, 2023

Use a validation script on the dropdown:

For example:

 

if(event.value == "Larry")
{
    this.getField("Address").value = "Larry's Address";
}
else if(event.value == "John")
{
    this.getField("Address").value = "John's Address";
}
else
{
    this.getField("Address").value = "";
}

 

In this code the names and addresses are hard coded in the script. Its simple but limited. If you ever need to add or change names/addresses you'll have to edit the code. A better approach is to use a document level variable to hold a list of names/addresses that can then be used to populate both the entries in the dropdown and the address of the selected item. 

Here's an article that covers this technique. It's really old, but still good. 

 https://acrobatusers.com/tutorials/change_another_field/

 

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

View solution in original post

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 ,
Mar 07, 2023 Mar 07, 2023

Use a validation script on the dropdown:

For example:

 

if(event.value == "Larry")
{
    this.getField("Address").value = "Larry's Address";
}
else if(event.value == "John")
{
    this.getField("Address").value = "John's Address";
}
else
{
    this.getField("Address").value = "";
}

 

In this code the names and addresses are hard coded in the script. Its simple but limited. If you ever need to add or change names/addresses you'll have to edit the code. A better approach is to use a document level variable to hold a list of names/addresses that can then be used to populate both the entries in the dropdown and the address of the selected item. 

Here's an article that covers this technique. It's really old, but still good. 

 https://acrobatusers.com/tutorials/change_another_field/

 

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

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 ,
Mar 07, 2023 Mar 07, 2023

Thank you, will try this immediately!

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 ,
Mar 07, 2023 Mar 07, 2023
LATEST

It worked, thank you!  

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