Skip to main content
lzacharyjw
Participant
April 19, 2018
Question

Percentage Color Change

  • April 19, 2018
  • 2 replies
  • 1522 views

Ok i am setting a script that i need it to calculate a percentage. if the percentage is over 30% it needs to go to red, if it's below it can stay in black.  i'm going off a V3/V4

V3-Payment

V4-Income

any ideas on how to get this setup for red?

This is what it's using right now with the Field Properties Format being Set to Percentage

(function () { 

 

    // Get the field values, as numbers 

    var v3 = +getField("payment").value; 

    var v4 = +getField("ApplicantsTotalNetIncome").value; 

    var v = v3 / v4;

   

    if (!isNaN(v) && v4 != 0) { 

        event.value = v; 

    } else { 

        event.value = ""; 

    } 

 

})(); 

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
June 28, 2018

Change this part of the code:

if (!isNaN(v) && v4 != 0) {

    event.value = v;

}

To this:

if (!isNaN(v) && v4 != 0) {

    event.value = v;

    event.target.textColor = (v>0.3) ? color.red : color.black;

}

PS. For future questions about scripts in Acrobat you'll be better off using this forum: JavaScript

sinious
Legend
May 21, 2018

If you're trying to change the textColor and fillColor properties as mentioned many times in these forums. Here's a random post.