Highlighted

How to change the field background color and text depending on condition

Explorer ,
Nov 17, 2020

Copy link to clipboard

Copied

Good day!

 

I have a computed field in fillable PDF (Total_Percentage is the field name).

 

I waht the background color of the field and text to change depending on the following conditins:

 

If Total_Percentage is < 100, I want the background to be yellow and text to be black

If Total_Percentage is = 100, I want the background to be green and text to be white

If Total_Percentage is > 100, I want the background to be red and text to be white.

 

I search in YouTube for solution and saw one but cannot make it work.

 

Thank you!

Try this code  as validation script:

if(event.value <= 99){
event.target.fillColor = color.yellow;
event.target.textColor = color.black;}
else if (event.value == 100){
event.target.fillColor = color.green;
event.target.textColor = color.white;}
else if(event.value >= 101){
event.target.fillColor = color.red;
event.target.textColor = color.white;}

TOPICS
Create PDFs, PDF forms

Views

39

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

How to change the field background color and text depending on condition

Explorer ,
Nov 17, 2020

Copy link to clipboard

Copied

Good day!

 

I have a computed field in fillable PDF (Total_Percentage is the field name).

 

I waht the background color of the field and text to change depending on the following conditins:

 

If Total_Percentage is < 100, I want the background to be yellow and text to be black

If Total_Percentage is = 100, I want the background to be green and text to be white

If Total_Percentage is > 100, I want the background to be red and text to be white.

 

I search in YouTube for solution and saw one but cannot make it work.

 

Thank you!

Try this code  as validation script:

if(event.value <= 99){
event.target.fillColor = color.yellow;
event.target.textColor = color.black;}
else if (event.value == 100){
event.target.fillColor = color.green;
event.target.textColor = color.white;}
else if(event.value >= 101){
event.target.fillColor = color.red;
event.target.textColor = color.white;}

TOPICS
Create PDFs, PDF forms

Views

40

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
Nov 17, 2020 0
Adobe Community Professional ,
Nov 17, 2020

Copy link to clipboard

Copied

You can use a custom calculation script in the Total_Percentage field:

 

var f = event.target;

// If Total_Percentage is < 100, I want the background to be yellow and text to be black

if (f.value <= 99) {
f.fillColor = color.yellow;
f.textColor = color.black;
} else {

// If Total_Percentage is = 100, I want the background to be green and text to be white
if (f.value === 100) {
f.fillColor = color.green;
f.textColor = color.white;
} else {

// If Total_Percentage is > 100, I want the background to be red and text to be white.

if (f.value >= 101) {
f.fillColor = color.red;
f.textColor = color.white;
}
}
}

 

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
Reply
Loading...
Nov 17, 2020 0
Engaged ,
Nov 17, 2020

Copy link to clipboard

Copied

Just to add up, if you have field formated as percentage change numbers in code:

99 to 0.99

100 to 1

101 to 1.01

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
Reply
Loading...
Nov 17, 2020 0
Explorer ,
Nov 18, 2020

Copy link to clipboard

Copied

Thanks for replying.

I tried the solution you have provided.

First, I could not add the script in "Custom calculation script" because I am using "Value is the +sum of the following fields| to compute for the Total_Percentage.

I tested putting the script in "Run custom validation script" under the Validate tab.and these are the result.

I don't know if this is the result of putting the script you have provided in "Run custom validation script"

 

Also Nasa commented on the format I used to defined the percentage. I defined the percentage fields as numeric (whole number) without decimal places.

Test Result.jpg

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
Reply
Loading...
Nov 18, 2020 0
Engaged ,
Nov 18, 2020

Copy link to clipboard

Copied

Try this code  as validation script:

if(event.value <= 99){
event.target.fillColor = color.yellow;
event.target.textColor = color.black;}
else if (event.value == 100){
event.target.fillColor = color.green;
event.target.textColor = color.white;}
else if(event.value >= 101){
event.target.fillColor = color.red;
event.target.textColor = color.white;}

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
Reply
Loading...
Nov 18, 2020 0
Explorer ,
Nov 18, 2020

Copy link to clipboard

Copied

Hi Nesa,

 

The solution you have provided works. Thank a lot.

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
Reply
Loading...
Nov 18, 2020 0