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!

Nesa Nurani
Community Expert
Community Expert
February 24, 2022

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;

Participant
February 24, 2022

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. 

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;