Copy link to clipboard
Copied
Hi. I'm currently using Adobe Acrobat PDF. My objective is to have the text fill color change based on the selection from a dropdown list.
This is the code I used. However, I noticed that the colors for Low, Moderate, and Extreme do not function. Can someone help me about this? Thank you.
var dropdownValue = this.getField("Dropdown2").value;
var targetField = this.getField("Text4");
switch(dropdownValue) {
case "-Select-":
targetField.fillColor = color.white;
break;
case "Negligible":
targetField.fillColor = color.gray;
break;
case "Low":
targetField.fillColor = color.greenyellow;
break;
case "Moderate":
targetField.fillColor = color.amber;
break;
case "High":
targetField.fillColor = color.red;
break;
case "Extreme":
targetField.fillColor = color.guardsmanred;
break;
default:
targetField.fillColor = color.transparent;
break;
}
Copy link to clipboard
Copied
You can't use: greenyellow, amber and guardsmanred, you need to use RGB or CMYK values.
You can learn how to do it here:
https://acrobatusers.com/tutorials/using-colors-acrobat-javascript/
Here is an example for 'amber' color with RGB value 244, 149, 29
use like this:
case "Moderate":
targetField.fillColor = ["RGB", 244/255, 149/255, 29/255];
break;
Copy link to clipboard
Copied
You can't use: greenyellow, amber and guardsmanred, you need to use RGB or CMYK values.
You can learn how to do it here:
https://acrobatusers.com/tutorials/using-colors-acrobat-javascript/
Here is an example for 'amber' color with RGB value 244, 149, 29
use like this:
case "Moderate":
targetField.fillColor = ["RGB", 244/255, 149/255, 29/255];
break;
Copy link to clipboard
Copied
Thank you so much, Nesa. I've resolved this issue, but when I attempt to send it to a recipient, the conditions cease to function. Do you know how to resolve this?
Copy link to clipboard
Copied
What exactly happens?
Copy link to clipboard
Copied
The JavaScript conditions were working perfectly when I previewed them. However, when I tested by sending the PDF to a recipient, the JavaScript no longer worked. Additionally, when I selected a specific option from the dropdown, the fill color did not function as expected.
Copy link to clipboard
Copied
What exactly means 'the fill color did not function as expected'?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now