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

Writing a script in a PDF form so colour of text changes based on a value.

Community Beginner ,
Aug 18, 2023 Aug 18, 2023

I have a simple script but not sure what is wrong. Basically if the number input to the form is less than, for example, 5. Then turn the font colour red. It works but.. not if you input 0.

 

var A = Number(this.getField("Quantity").valueAsString);

if(A){
 if(A<5)
 event.target.textColor = color.red;
 else
 event.target.textColor = color.black;}

 

TOPICS
PDF , PDF forms
378
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 ,
Aug 18, 2023 Aug 18, 2023

The first if statement blocks the 0 input, because a value of 0 converts to False.

Remove it. Here's an update.

var A = Number(this.getField("Quantity").valueAsString);

if(A<5)
   event.target.textColor = color.red;
else
   event.target.textColor = color.black;

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Aug 18, 2023 Aug 18, 2023

The first if statement blocks the 0 input, because a value of 0 converts to False.

Remove it. Here's an update.

var A = Number(this.getField("Quantity").valueAsString);

if(A<5)
   event.target.textColor = color.red;
else
   event.target.textColor = color.black;

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Aug 18, 2023 Aug 18, 2023
LATEST

This has solved the issue. Much appreciated! 

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