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

Text fill color change based on the selection from a dropdown list

Community Beginner ,
Nov 29, 2023 Nov 29, 2023

Hi. I'm currently using Adobe Acrobat PDF. My objective is to have the text fill color change based on the selection from a dropdown list. 

This is the code I used. However, I noticed that the colors for Low, Moderate, and Extreme do not function. Can someone help me about this? Thank you.


var dropdownValue = this.getField("Dropdown2").value;
var targetField = this.getField("Text4");


switch(dropdownValue) {
case "-Select-":
targetField.fillColor = color.white;
break;
case "Negligible":
targetField.fillColor = color.gray;
break;
case "Low":
targetField.fillColor = color.greenyellow;
break;
case "Moderate":
targetField.fillColor = color.amber;
break;
case "High":
targetField.fillColor = color.red;
break;
case "Extreme":
targetField.fillColor = color.guardsmanred;
break;
default:
targetField.fillColor = color.transparent;
break;
}

TOPICS
Modern Acrobat , PDF
995
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
Community Expert ,
Nov 29, 2023 Nov 29, 2023

You can't use: greenyellow, amber and guardsmanred, you need to use RGB or CMYK values.

You can learn how to do it here:

https://acrobatusers.com/tutorials/using-colors-acrobat-javascript/ 

Here is an example for 'amber' color with RGB value 244, 149, 29

use like this:

case "Moderate":
targetField.fillColor = ["RGB", 244/255, 149/255, 29/255];
break;

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
Community Expert ,
Nov 29, 2023 Nov 29, 2023

You can't use: greenyellow, amber and guardsmanred, you need to use RGB or CMYK values.

You can learn how to do it here:

https://acrobatusers.com/tutorials/using-colors-acrobat-javascript/ 

Here is an example for 'amber' color with RGB value 244, 149, 29

use like this:

case "Moderate":
targetField.fillColor = ["RGB", 244/255, 149/255, 29/255];
break;

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 Beginner ,
Nov 30, 2023 Nov 30, 2023

Thank you so much, Nesa. I've resolved this issue, but when I attempt to send it to a recipient, the conditions cease to function. Do you know how to resolve this?

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 ,
Nov 30, 2023 Nov 30, 2023

What exactly happens?

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 Beginner ,
Dec 01, 2023 Dec 01, 2023

The JavaScript conditions were working perfectly when I previewed them. However, when I tested by sending the PDF to a recipient, the JavaScript no longer worked. Additionally, when I selected a specific option from the dropdown, the fill color did not function as expected.

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 ,
Dec 01, 2023 Dec 01, 2023
LATEST

What exactly means  'the fill color did not function as expected'?

 

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