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.
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.
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.
Copy link to clipboard
Copied
Brilliant! Thank you so much!
I really appreciate your help.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now