Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Conditional Formatting Color fill in Adobe Acrobat DC

New Here ,
Aug 28, 2018 Aug 28, 2018

I am trying to conditionally format a field in my PDF to fill with a certain color based on the selected dropdown list's value. It seems i have gotten some traction, but the only color that works is red, and it does not change colors if I select a different value from my dropdown. I need help with my Javascript. Here is what I have so far:

var v = this.getField("Dropdown4.5").value;

     if (v="Business Now") {event.target.fillColor = color.green;}

     if (v="Business Future") {event.target.fillColor = color.blue;}

     if (v="Daily To-Do's") {event.target.fillColor = color.red;}                   

     if (v="Marketing") {event.target.fillColor = color.orange;}

     if (v="Learning Plan") {event.target.fillColor = color.yellow;}

Stack 3.PNG

5.7K
Translate
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
1 ACCEPTED SOLUTION
LEGEND ,
Aug 28, 2018 Aug 28, 2018

That first line is missing getField, so it should be:

var v = getField("Dropdown4.8").value;

though it's best to get into the habit of using the valueAsString property instead when you'll be dealing with a field value as a string:

var v = getField("Dropdown4.8").valueAsString;

View solution in original post

Translate
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 ,
Apr 07, 2025 Apr 07, 2025

I've made the suggested edits and the field color is still not changing in Preview mode. 

 

var triggerValue = this.getField("Vendor ScoreRow2").value;
var targetField = this.getField("Vendor ScoreRow2").valueAsString;
if (triggerValue === "100") {targetField.fillColor = color.green;
} else if (triggerValue === "75") {targetField.fillColor = color.blue;
} else if (triggerValue === "50") {targetField.fillColor = color.yellow;
} else if (triggerValue === "25") {targetField.fillColor = ["RGB", 255/255, 165/255, 0/255];
} else if (triggerValue === "0") {targetField.fillColor = color.red;
}

Translate
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
Community Expert ,
Apr 07, 2025 Apr 07, 2025

Sorry, my first correction was incorrect. Change it back.

And test it in regular viewing mode, not in preview mode.

Translate
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 ,
Apr 07, 2025 Apr 07, 2025

No problem. I changed it back and it's still not working in regular view mode. I've included the file to see if there is something else I'm missing that is preventing the appropriate formatting. 

Translate
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
Community Expert ,
Apr 07, 2025 Apr 07, 2025

Change the first line to:

var triggerValue = this.getField("Vendor ScoreRow2").valueAsString;

Also, make sure that the Fields Highlighting is disabled so you could see the fill color.

Translate
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 ,
Apr 07, 2025 Apr 07, 2025

That worked! Much appreciated!

 

Is there a code I can add to revert the fields back to white or no color if they are left blank? 

Translate
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
Community Expert ,
Apr 07, 2025 Apr 07, 2025
LATEST

Sure. Add this to the end of the code:

 

else targetField.fillColor = color.transparent;

Translate
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 ,
Oct 14, 2020 Oct 14, 2020

Hi! 

I am trying to conditionally format a field in my PDF to fill with a certain color based on the selected dropdown list's value. I tried adapting solutions provided to others with the same request. Unfortunately I don't understand enough about the script to come up with the right solution. I've been trying for days and would really appreciate help. 

 

Thank you!!

Translate
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
Community Expert ,
Oct 14, 2020 Oct 14, 2020

You need to provide more details if you want to have help... What did you try? What were the results? What are you tryign to achieve, exactly?

Translate
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
Community Expert ,
Mar 08, 2025 Mar 08, 2025

[MOVED TO THE ACROBAT DISCUSSIONS]


Acrobate du PDF, InDesigner et Photoshopographe
Translate
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