Participating Frequently
July 23, 2025
Question
Form - Conditional format a field's fill colour based on a drop-down list selection
- July 23, 2025
- 2 replies
- 372 views
Hi Acrobat users,
I have modified an existing form to meet a client's request. To add visual impact, I want to conditionally format the fill colour of the Action drop-down list and the adjoining text field. I desire to use custom RGB codes for readability purposes. A sample report is attached.
I am facing the following problems:
- The colour of the drop-down field does not change when a selection is made.
- The selection of an item from the drop-down list is not triggering the conditional formatting for the Comments text field.
- I am not sure of the correct format when specifying custom RGB colours. 2 different formats in the code to indicate the different formats that have been attempted.
Below is my JavaScript code for the drop-down list.
if (event.value==" ") event.target.fillColor = color.transparent;
else if (event.value=="Non-compliant") event.target.fillColor = [“RGB”, 0, 0.41, 0.38];
else if (event.value=="Recommendation") event.target.fillColor = [“RGB”, 0, 0.7, 0.28];
Below is my JavaScript code for the text field.
var selectedValue = “event.target.value”; // Get the selected value from the dropdown
var targetField = this.getField("Item Action.1"); // Replace with your field name
// Change the background color based on the dropdown value
if (selectedValue === " ") {
targetField.fillColor = color.transparent;
} else if (selectedValue === "Non-compliant") {
targetField.fillColor = [“RGB”, 0, 105/255, 97/255];
} else if (selectedValue === "Recommendation") {
targetField.fillColor = [“RGB”, 0, 179/255, 71/255];
} else {
targetField.fillColor = color.white; // Default color
}
If I can receive some assistance with these challenges, this would be greatly appreciated.
Many thanks,
Tim
