Custom formatting for drop down menu color change.
Copy link to clipboard
Copied
Hi,
Being a beginner at Javascript and have been looking and searching for the right code.
I really hope that you can help me.
I have created a fillable PDF with a dropdown menus. The dropdowns have 3 options and want each option to result in a color.
This is the script I currently have been working on i'm able to get the color to change for "Complete" but not for "In Progress" or "Not Started"
if (event.value=="Complete")
event.target.fillColor = color.green;
else if (event.value=="In_Progress")
event.target.fillColor = color.yellow;
else if (event.value=="NotÂ_Started")
event.target.fillColor = color.Red;
event.target.fillColor = color.transparent;
Copy link to clipboard
Copied
-It's "color.red", not "color.Red".
-"color.yellow" is a CMYK color, not an RGB one. Try it with an RGB code, instead.
Copy link to clipboard
Copied
I changed it to "color.red" still did not work
Copy link to clipboard
Copied
The last line overrides the others. Looks like you are missing an "else"
And the "Commit value immediately" option should be checked.
if (event.value=="Complete")
event.target.fillColor = color.green;
else if (event.value=="In_Progress")
event.target.fillColor = color.yellow;
else if (event.value=="NotÂ_Started")
event.target.fillColor = color.Red;
else
event.target.fillColor = color.transparent;
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
++Adding to the topic,
This also worked for me as a Custom Format Script.
if (event.value == "Complete") event.target.fillColor = color.green;
else {
if (event.value == "In Progress")event.target.fillColor = color.yellow;
else {
if (event.value = "Not Started")event.target.fillColor = color.red;
}
}
I am not sure what condition will trigger the transparent field color property. Is there a blank space that allows the user to select from the dropdown menu?
Copy link to clipboard
Copied
Yes, there is a blank space. That script seemed to work best but yellow is not selcted for "In Progress" it comes up as red. Any thoughts?
Copy link to clipboard
Copied
++ EDITED REPLY, added screenshot
Well, what worked for me with no issues is the example below as a Custom Format Script:
if (event.value =="" || event.value == " ") event.target.fillColor = color.transparent;
else {
if (event.value == "Complete") event.target.fillColor = color.green;
else {
if (event.value == "In_Progress")event.target.fillColor = color.yellow;
else {
if (event.value = "NotÂ_Started")event.target.fillColor = color.red;
}
}
}
NOTE: It worked for me too as a custom calculation script
As mentioned by Thom Parker, in the Dropdown Properties dialogue window, go to the "Options" tab, and you must tick the checkbox "Commit selected values immediately" for the the script to commit the field color properties as soon as a selection is made in the dropdown; otherwise you'll experience a delay or will not work at all.
See slide below:
Copy link to clipboard
Copied
Is it "In Progress" or "In_Progress"? You have to make sure the string in your code matches the actual value PERFECTLY, including upper/lower-case letters, spaces, etc.
Copy link to clipboard
Copied
Than you for noting that Try67.
In my example slide I was testing the script with a space instead of the underscore character for those listed items.

