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

Using Drop-down to dynamically format separate text field, but target text field doesn't auto update

New Here ,
Feb 01, 2024 Feb 01, 2024

Copy link to clipboard

Copied

I'm using Acrobat Pro.
I'm trying to get a text field to dynamically change its fill color according to the selection in a separate dropdown box. The code works, changing options in the dropdown changes the fill color, but it doesn't update unless I edit the text in the target text field, then click on a separate object. I'm hoping to find a solution where changing the value in the dropdown field automatically updates the target text field.

 

I have tried inputing the script  in:

Text Field Properties/Format/ Custom Keystroke Script

as well as:

Text Field Properties/Format/ Custom Format Script

I get the same results.

 

In the Dropdown Properties menu, I checked the box "Commit Selected value immediately"

I'm not a JavaScript programmer; I just figured out how to do this today.

var f = this.getField("Dropdown1").value; {

if(f=="Option1")

event.target.fillColor = ["RGB", 255/255,255/255,110/255];

else if(f=="Option2")

event.target.fillColor = ["RGB", 110/255,245/255,255/255];

}

 

Thank you for any help you can offer.

 

TOPICS
Create PDFs , How to , JavaScript , PDF forms

Views

212

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 , Feb 01, 2024 Feb 01, 2024

The only script that is run on a field when another field changes is the calculation. The keystroke and format are only run when the field containing those event scripts is changed. This is why you needed to edit the text field.   

 

So you have two options for a solution:

1) Calculation script on the text field. (Best used when input is coming from multiple locations)

2) Keystroke, format, or validate script on the dropdown. (Best used when all action is driven from the selection)

 

From your d

...

Votes

Translate

Translate
Community Expert ,
Feb 01, 2024 Feb 01, 2024

Copy link to clipboard

Copied

The only script that is run on a field when another field changes is the calculation. The keystroke and format are only run when the field containing those event scripts is changed. This is why you needed to edit the text field.   

 

So you have two options for a solution:

1) Calculation script on the text field. (Best used when input is coming from multiple locations)

2) Keystroke, format, or validate script on the dropdown. (Best used when all action is driven from the selection)

 

From your description, #2 is the best option. Place your script on the Custom Validation script for the dropdown.   But change the source and target fields around. 

 

 

 

if(event.value == "Option1")
     this.getField("TextField").fillColor = ["RGB", 255/255,255/255,110/255];
else if(event.value == "Option2")
     this.getField("TextField").fillColor = ["RGB", 110/255,245/255,255/255];

 

 

 

Change "TextField" to the name of the actual text field on your form.  And be sure to delete all other scripts that affect this behavior. 

 

 

 

 

 

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
New Here ,
Feb 01, 2024 Feb 01, 2024

Copy link to clipboard

Copied

LATEST

Brilliant!  Thank you so much!
I really appreciate 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