Skip to main content
New Participant
July 30, 2020
Answered

Conditional formatting based on value of another form field

  • July 30, 2020
  • 2 replies
  • 3625 views

Hello! I need to change bg color of a field simply based on the text contents of another field on a different page. I've been researching for hours trying to find this seemingly simple code and tried numerous times based on other forums but have been unsuccessful. I have come across numerous answers for numerical values and calculations but nothing for a simple text input.

 

For example, I need the "RingGear" field on page 1 to be highlighted green if the value of "RingGearValue" (on page 4)  = "OK", and highlighted red if the value "RingGearValue" = "CAUTION", otherwise transparent.

 

Thank you!

This topic has been closed for replies.
Correct answer Nesa Nurani

Use this as Custom calculation script of "RingGear" field

var e = this.getField("RingGearValue").value;
var f = this.getField("RingGear");
if( e == "OK"){
  f.fillColor = color.green;
}else
 if( e == "CAUTION"){
  f.fillColor = color.red;
}else f.fillColor = color.transparent;

2 replies

Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
July 30, 2020

Use this as Custom calculation script of "RingGear" field

var e = this.getField("RingGearValue").value;
var f = this.getField("RingGear");
if( e == "OK"){
  f.fillColor = color.green;
}else
 if( e == "CAUTION"){
  f.fillColor = color.red;
}else f.fillColor = color.transparent;
Inspiring
October 24, 2022

I have a similar problem that I can't figure out. I have two fields that require a different set of calculations. Textbox1 totals all of the available service time opportunities that the user inputs in other fields. Textbox2, subtracts the start of the workday from the end of the workday. I need to make sure that the service time opportunity minutes matches the exact amount of minutes in Textbox2. I already have the calculations in place and they work fine. I would like the background color in Textbox2 to turn red if they are not equal and green if they are. Do you know how I can do this?

Inspiring
October 25, 2022

You are trying to compare a string, you need to make sure that value is a number:

Number(this.getField("Textbox8").valueAsString)


I appologize, I'm still too new at this to understand what I did wrong. Can I see your proposed solution in a complete script?

Bernd Alheit
Community Expert
July 30, 2020

You can check the content of text fields like this:

if (this.getField("RingGearValue").value  == "OK") {

 

}