Skip to main content
stepheng54012748
Known Participant
January 19, 2024
Answered

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

  • January 19, 2024
  • 1 reply
  • 916 views

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

 

Correct answer Thom Parker

Use this script.

 

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

 

 

1 reply

Thom Parker
Thom ParkerCorrect answer
Inspiring
January 19, 2024

Use this script.

 

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

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
New Participant
January 25, 2024

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? 

 

 

 

Thom Parker
Inspiring
January 26, 2024

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 PDFScriptingUse the Acrobat JavaScript Reference early and often