Copy link to clipboard
Copied
HI! I want to learn how I can change the color of a text field based on specific selections from a drop down menu. If let's say "Medicaid" is selected from drop down menu field "Insurance Company Name", I would like the text field "Medicaid" to highlight yellow. How can I do that with java script? Thanks!
Copy link to clipboard
Copied
As the custom calculation script of text field enter the following code:
event.target.fillColor = (this.getField("Insurance Company Name").valueAsString=="Medicaid") ? color.yellow : color.transparent;
Copy link to clipboard
Copied
As the custom calculation script of text field enter the following code:
event.target.fillColor = (this.getField("Insurance Company Name").valueAsString=="Medicaid") ? color.yellow : color.transparent;
Copy link to clipboard
Copied
You rock! That worked! I have multiple selections that if selected from the drop down I want to change the textfield to yellow. Where would I enter the other selections in your script?
Copy link to clipboard
Copied
You can do it like this:
var v = this.getField("Insurance Company Name").valueAsString;
event.target.fillColor = (v=="Medicaid" || v=="Something else" || v=="Yet another thing") ? color.yellow : color.transparent;
Copy link to clipboard
Copied
Thank you soooooo much! That worked perfectly!
Copy link to clipboard
Copied
Hi, I have another question
What should I write if I want to create different colors for different dropdown options?
Many thanks 🙂
Copy link to clipboard
Copied
What should I write if I want to create different colors for different text options?
Copy link to clipboard
Copied
Hi,
See here another great little script by Try67: https://community.adobe.com/t5/acrobat/can-the-color-of-text-be-changed-based-on-the-what-the-text-f...
Copy link to clipboard
Copied
Hello,
Can someone please help me? I have a dropdown menu in PDF forms in which there are 2 options (text) and I want based on the option that someone chooses the text colour to change. How can I code this in java?
Thank you!
Copy link to clipboard
Copied
Well, your inquiry is already addressed here in this thread using Acrobat JavaScript not Java.
Acrobat JavaScript is the programming language that the Adobe Acrobat use.
Copy link to clipboard
Copied
Hello,
I am and in need the same function. The field is called "Ankle DFR" and the selection options are (no commas): Limited, WRL, and Hypermobile. I would like it to turn yellow when I select "Limited" and "Hypermobile".
So I created a drop down menu, opened properities, clicked the calculate tab, and entered the following in the Custom Calculation section:
event.target.fillColor = (this.getField("Ankle DFR").valueAsString=="Limited") ? color.yellow : color.transparent;
However, it only goes yellow when I click once and see the list of options. But when I select the desired choice, Limited, it goes back to its original color. I would like it to remain yellow (or whatever color), when I select anything other than WRL. Thanks in advance for any help!
Copy link to clipboard
Copied
At what text field does you use the script?
Copy link to clipboard
Copied
Hi Bernd
Thank you for your reply. Unfortunately I don't quite understand your message. Could you please rephrase? Thanks again.
Copy link to clipboard
Copied
Want you change the color of a text field based on specific selections from a drop down menu?
Copy link to clipboard
Copied
If you want yellow for anything other then "WRL" then use like this and in dropdown field properties under options tab tick 'Commit selected value immediately':
event.target.fillColor = (this.getField("Ankle DFR").valueAsString=="WRL") ? color.transparent : color.yellow;
Copy link to clipboard
Copied
Hi Nesa
Thank you for your response. Where do I paste your code? I did as you suggested by clicking "Commit selected value immediately" and then moved on to the Calculate tab and entered your code in the Custom Calculation section. However, the same thing happens where the drop down menu will turn yellow when I bring up the down menu to see all the options but once I select it seems remains the initial color, not yellow.
Copy link to clipboard
Copied
You probably have active field highlights, try turn them off in preferences -> forms -> 'Show border hover color for fields'.
Copy link to clipboard
Copied
Hi Nesa,
Thank you so much for your suggestions. My problem has been successfully solved.

