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
  • 919 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
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
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
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? 

 

 

 

Nesa Nurani
Community Expert
Community Expert
January 26, 2024

Do you use Acrobat to fill form?

Did you use a calculation script to calculate the total?