Skip to main content
Known Participant
March 15, 2019
Answered

Change Color of Text Field from Drop Down Menu Selection

  • March 15, 2019
  • 2 replies
  • 7988 views

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!

This topic has been closed for replies.
Correct answer try67

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;

2 replies

Participant
February 24, 2022

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!

Bernd Alheit
Community Expert
Community Expert
February 24, 2022

At what text field does you use the script?

Participant
February 24, 2022

Hi Bernd

 

Thank you for your reply. Unfortunately I don't quite understand your message. Could you please rephrase? Thanks again. 

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
March 15, 2019

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;

Known Participant
March 15, 2019

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?

try67
Community Expert
Community Expert
March 15, 2019

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;