Skip to main content
Participant
November 1, 2023
Question

Struggling to run a script to change colours in a drop down list

  • November 1, 2023
  • 3 replies
  • 1594 views

Hi, I am putting together an order form in PDF format using Acrobat DC. I have a series of drop-down lists in which I need the background colour to change based on which answer is selected from the dropdown. I have tried to run a basic script, a custom validation script, but it's just not working!

Any advise, please?

Script :-

if (event.value=="New")

event.target.fillColor = color.red;

else if (event.value=="Renewal")

event.target.fillColor = color.magenta;

else if (event.value=="Set Up Only")

event.target.fillColor = color.yellow;

else

event.target.fillColor = color.transparent;

 

This topic has been closed for replies.

3 replies

try67
Community Expert
Community Expert
November 1, 2023

The code seems fine. Check the JS Console for errors when changing the field's value.

Also, make sure to set the option to commit the selected value immediately and to disable the Fields Highlighting option in the application to be able to see the new color.

InfoPulsePro
Participant
November 1, 2023

It appears that you're attempting to use a script to change the background color of a dropdown list in a PDF form based on the selected answer. The script you've provided is on the right track, but there are a couple of issues with it. Below is a corrected version of your script:

```javascript
// Run the script when the dropdown selection changes
this.getField("YourDropDownFieldName").setAction("Keystroke", function() {
var selectedValue = event.value;
var dropdownField = event.target;

if (selectedValue === "New") {
dropdownField.fillColor = color.red;
} else if (selectedValue === "Renewal") {
dropdownField.fillColor = color.magenta;
} else if (selectedValue === "Set Up Only") {
dropdownField.fillColor = color.yellow;
} else {
dropdownField.fillColor = color.transparent;
}
});
```

Please make the following changes:

1. Replace `"YourDropDownFieldName"` with the actual name of your dropdown field in the `this.getField` method. You should use the name of the dropdown field as it appears in your PDF form.

2. This script is set to run when a keystroke event occurs in the dropdown field. It checks the selected value and changes the background color accordingly. This should help you achieve the desired behavior.

3. Make sure to place this script in the "Custom Calculation Script" section of the dropdown field's properties in Adobe Acrobat. This is where the script will be executed when the dropdown selection changes.

By making these adjustments and placing the script in the appropriate location, your dropdown list should update its background color based on the selected value as expected. Credit Infopulsepro [Link removed]

All about information, knowledge, and how to questions answer.
Inspiring
November 1, 2023

@InfoPulseProIf you don't know what you're doing, please stop posting scripts from ChatGPT.

Bernd Alheit
Community Expert
Community Expert
November 1, 2023

What happens when you use it?

Steph5FC5Author
Participant
November 1, 2023

Nothing! When I test the form and select each drop-down option, nothing changes.

Bernd Alheit
Community Expert
Community Expert
November 1, 2023

Have you checked the properties of the dropdown?