Copy link to clipboard
Copied
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.***
1 Correct answer
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks for your prompt response. I ended up doing this with a few other variations dependant on value.

