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

Java or Validation script that will give a negative result no matter if the number entered..

Participant ,
Jan 19, 2024 Jan 19, 2024

Copy link to clipboard

Copied

Hello,

 

Can anyone offer any suggestions on how to write a Java or Validation script so the result is always a negative number?  The PDF I'm working on has a field (which is named l6) that is a field that one can enter a number.  I'd like the number to always be a negative, so if one enters 3,000 then when they hit enter I'd like the number to be -3,000.  If they enter -3,000 then I'd like the number to be -3,000 for the field (l6) that they are entering the number for.  I feel like a validation script is the way to go with this but honestly i have no idea.  Thank you in advance for any input

 

TOPICS
Edit and convert PDFs , How to , JavaScript , Modern Acrobat , PDF , PDF forms

Views

115

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
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 19, 2024 Jan 19, 2024

Use this script.

 

if(event.value > 0) event.value = -event.value;

 

 

Votes

Translate

Translate
Community Expert ,
Jan 19, 2024 Jan 19, 2024

Copy link to clipboard

Copied

Use this script.

 

if(event.value > 0) event.value = -event.value;

 

 

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

Votes

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
community guidelines
Community Beginner ,
Jan 25, 2024 Jan 25, 2024

Copy link to clipboard

Copied

I used if(event.value > 0) event.value = -event.value; to make the row for the "Less: (Advance)" always a negative number. 

The row below it, is the totals, so in Adobe, i created the calculation formula to be a the sum of everything on that column (which would really subtract the "Less: (Advance)" ). 

 

When I do "preview" in Adobe, all the validations and calculations work.


When I save the file as a PDF into my computer, and when I try to fill out that file from the hard drive, the calculation adds the  "Less: (Advance)" row instead of it treating it as a negative number.  How can I get it to work? 

 

KB60191_0-1706215500141.png

 

 

Votes

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
community guidelines
Community Expert ,
Jan 25, 2024 Jan 25, 2024

Copy link to clipboard

Copied

Do you use Acrobat to fill form?

Did you use a calculation script to calculate the total?

Votes

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
community guidelines
Community Expert ,
Jan 26, 2024 Jan 26, 2024

Copy link to clipboard

Copied

LATEST

Also, that code doesn't make the value "always" negative. It negates the current value, which if it is already negative, makes it positive. And the script is intended to be used as a Validation Script. If you used it as a calculation script, then you must ensure the calculation order is setup correctly. 

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

Votes

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
community guidelines