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

Change drop-down choices based on previous drop-down choice

New Here ,
Jan 15, 2021 Jan 15, 2021

Copy link to clipboard

Copied

Hi. I'm trying to dynamically change the choices in a drop-down field based on what option was selected in the previous drop-down field. I'm using the following formula as my template:

 

if (this.getField("Drop-Down 1").value == "A"){

this.getField("Drop-Down 2").setItems([" ", "A1", "A2", "A3"])

}

else if (this.getField("Drop-Down 1").value == "B"){

this.getField("Drop-Down 2").setItems([" ", "B1", "B2", "B2"])

}

 

When using this template, the second drop-down is correctly adjusting what options it shows. However, after selecting an option and clicking away from the field, the field keeps reverting back to blank instead of the option I selected.

 

Any help figuring out what I'm doing wrong would be greatly appreciated.

TOPICS
How to , JavaScript , PDF forms

Views

488

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

correct answers 1 Correct answer

Community Expert , Jan 15, 2021 Jan 15, 2021

Where do you use code?

Put it in "Drop-Down 1" as validation script and change this.getField("Drop-Down 1").value to event.value.

Votes

Translate

Translate
Community Expert ,
Jan 15, 2021 Jan 15, 2021

Copy link to clipboard

Copied

Where do you use code?

Put it in "Drop-Down 1" as validation script and change this.getField("Drop-Down 1").value to event.value.

Votes

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
New Here ,
Jan 15, 2021 Jan 15, 2021

Copy link to clipboard

Copied

Hi Nesa,

 

The script is currently in the Custom Calculation for for Drop-Down 2.

 

I'm pretty new to this, so I apologize for not having a strong grasp of your suggestions. You're saying I should remove this script from where I have it in Drop-Down 2 and move it to a Validation script in Drop-Down 1? And changing to event.value, would it look like this:

 

if (event.value == "A"){

this.getField("Drop-Down 2").setItems([" ", "A1", "A2", "A3"])

}

else if (event.value == "B"){

this.getField("Drop-Down 2").setItems([" ", "B1", "B2", "B2"])

}

Votes

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 Expert ,
Jan 15, 2021 Jan 15, 2021

Copy link to clipboard

Copied

Yes, try that.

Votes

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
New Here ,
Jan 15, 2021 Jan 15, 2021

Copy link to clipboard

Copied

LATEST

Hi Nesa,

 

That did the trick! Thank you for your help!

Votes

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 Expert ,
Jan 15, 2021 Jan 15, 2021

Copy link to clipboard

Copied

Where does you use the script?

Votes

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 Expert ,
Jan 15, 2021 Jan 15, 2021

Copy link to clipboard

Copied

This question has been asked quite a bit. In fact, you'll find an article on the topic here:

https://acrobatusers.com/tutorials/js_list_combo_livecycle/

and Here:

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

 

 

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

Votes

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