Text Colour Custom Calculation/Validation Script?

New Here ,
Aug 18, 2019 Aug 18, 2019

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.***

TOPICS
Acrobat SDK and JavaScript

Views

108

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Aug 18, 2019 Aug 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.

Likes

Translate

Translate
Adobe Community Professional ,
Aug 18, 2019 Aug 18, 2019

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 18, 2019 Aug 18, 2019

Copy link to clipboard

Copied

LATEST

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines