Skip to main content
daring_Walrus5CE0
Participant
August 18, 2019
Answered

Text Colour Custom Calculation/Validation Script?

  • August 18, 2019
  • 2 replies
  • 585 views

Hi I'm creating a form which requires the comparison of two cells to show a cash saving. I would like to change the colour of the text in the savings cells/column based on whether they are equal to or less than zero. The default colour if greater than 0 should be green.

I have spent a while trawling the internet for a solution that works and whether the JS info should be in the calculation or in the validation. I have successfully got this calculation working. But cannot for the life of me suss the colour - I got close but alas no cigar.

(function () {

// Get field values as numbers

    var v1 = +getField("Competitor1.0").value;

    var v2 = +getField("OurPrice1.0").value;

    var v3 = +getField("Quantity1.0").value;

// calculate this field value

    event.value = v3 * (v1 - v2);

})();

My questions are as follows

- How do I create the colour script?

- Where should it be used (in the calculation/validation areas)?

Any help much appreciated.

***FIXED Myself.***

This topic has been closed for replies.
Correct answer try67

You can use either event. I would use the Calculation script. Add this after the event.value = ... line of your code:

event.target.textColor = (event.value>0) ? color.green : color.black;

You didn't specify what color should be used if the value is zero or less, so I assumed black.

2 replies

daring_Walrus5CE0
Participant
August 18, 2019

Thanks for your prompt response. I ended up doing this with a few other variations dependant on value.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 18, 2019

You can use either event. I would use the Calculation script. Add this after the event.value = ... line of your code:

event.target.textColor = (event.value>0) ? color.green : color.black;

You didn't specify what color should be used if the value is zero or less, so I assumed black.