Is it possible to change a filed background color based on a condition?

  • 0
  • 1
  • Question
  • Updated 3 years ago
  • Answered
I am using the following formula to change the field background color to red whenever  a score is less than a target. 

var number Trend=[Score]; 

If([Score]<[Cleaning Service - Target], "<div style=\"color:white;background-color:#FF0000;\"> " & $Trend & "<div>", "<div style=\"color:black;\"> " & $Trend & "<div>")


Now I would like to extend the formula to change the field background color to green when a score is greater than a target or remain unchanged when a score is equal to the target.

I have tried several combinations or this formula but keep getting errors.

Does any know how I can accomplish this task?

Any direction would be greatly appreciated.

Thank you,    
Photo of Jerry

Jerry

  • 0 Points

Posted 3 years ago

  • 0
  • 1
In QuickBase you can start an IF statement and then just keep listing your condition.  The formula will just take the first condition that is true and do that action.

So, try this:

var number Trend=[Score];

If(
[Score]<[Cleaning Service - Target],
    "<div style=\"color:white;background-color:#FF0000;\"> " & $Trend & "<div>",

[Score]>[Cleaning Service - Target],
    (insert your code here for the green result),

"<div style=\"color:black;\"> " & $Trend & "<div>")
Photo of Jerry

Jerry

  • 0 Points
This is what I have, but I get an error.

var number Trend=[Score];

If(
[Score]<[Cleaning Service - Target],
    "<div style=\"color:white;background-color:#FF0000;\"> " & $Trend & "<div>",

[Score]>[Cleaning Service - Target],
    <div style=\"color:white;background-color:#99FF33;\"> " & $Trend & "<div>",

"<div style=\"color:black;\"> " & $Trend & "<div>")
Photo of Jerry

Jerry

  • 0 Points
Sorry. Got it...
Right, missing that opening quote on that new line.  Glad it's working now!
Photo of Jerry

Jerry

  • 0 Points
Thank you very much