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

Field needs to be filled by user for difference calculation

Community Beginner ,
Aug 21, 2023 Aug 21, 2023

I need a difference calculation provided (positive or negative). An amount entered by a form user to calculate the difference. This is the information required on form:

Lorie3170995304uz_0-1692628769508.png

 

 

The user would enter the "Advanced Check Amount" and the "Cash owed toreturned" needs to show the difference, be it positive or negative. (Amount1-3  boxes are misc expenses)

Definitely not a pro here, so forgive me if it's something Captain Obvious would know lol.

I've exhausted research options and just want to know if this is possible or not. Thanks for anyone's help.

TOPICS
PDF forms
1.0K
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
2 ACCEPTED SOLUTIONS
Community Expert ,
Aug 21, 2023 Aug 21, 2023

This is a simple calculation. With Acrobat JavaScript it is possible to perform much, much more complicated operations.

You can read about simple scripting for calculations here:

https://www.pdfscripting.com/public/How-to-Write-a-Basic-PDF-Calculation-Script.cfm

 

You're ("Cash owed toreturned") calculation script might look something like this: 

 

 

event.value = this.getField("Advanced Check Amount").value - this.getField("Total Expenses").value;

 

 

However, to get the calculation correct we'd need to know exactly what fields are involved and how. 

 

 

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

It's always like that. Some small thing that gets overlooked. 

 

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

What is calculation?

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

This is a simple calculation. With Acrobat JavaScript it is possible to perform much, much more complicated operations.

You can read about simple scripting for calculations here:

https://www.pdfscripting.com/public/How-to-Write-a-Basic-PDF-Calculation-Script.cfm

 

You're ("Cash owed toreturned") calculation script might look something like this: 

 

 

event.value = this.getField("Advanced Check Amount").value - this.getField("Total Expenses").value;

 

 

However, to get the calculation correct we'd need to know exactly what fields are involved and how. 

 

 

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

The screenshot at the bottom will show what I'm looking for, I hope. I did a formula prior to posting here and could not get it to work. 

Lorie3170995304uz_1-1692638680843.png

 

The small column on the left is for Misc Expenses incurred and the Meals total is the top. All my auto calculations work except for getting the amount that is "owed" or needs to be "returned" to the traveler. So in my screenshot, all the variables are correct and in place to calculate that final number, be it positive cash (owed to traveler) or negative cash (traveler must return).

If this is clear as mud, please accept my apologies. Sometimes the smallest of things can cause the greatest of problems for someone, and I feel like that is where I'm at.

 

Lorie3170995304uz_0-1692638588502.png

 

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

I even changed spacing in between the minus sign and the words of the field...anything I could possibly think of, to no avail.

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

Spacing is meaningless.  To find out whats going on the first thing you need to do is look in the console window to see if there are any repported errors.  Press "Ctrl-J" to display the console. 

Here's a video tutorial on how to use it. 

https://www.pdfscripting.com/public/images/video/AcroJSIntro/AcroJSIntro_ConsoleWindow.cfm

 

 

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 Expert ,
Aug 22, 2023 Aug 22, 2023

What happens when you enter a value in this field?

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

If you are referring to the "cash owed toreturned" field, it's a read only field. I have other forms that are set up similar (read only for result) just using addition or multiplication.

I changed it to enter a value and it's holding that entry (see screenshots below). I'm going through the video for debugging that was provided earlier. All the dropdown choices for calculations work perfectly, but when entering the script (simplified or custom), not so much...unless it's one of the choices from the dropdown. I deliberately did several trials of that to make sure I knew the proper format for it to work. 

 

Example with and without manual entry:

Lorie3170995304uz_1-1692710989676.png 

  

Lorie3170995304uz_2-1692711096004.png

 

 

 

 

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

One word was missing from my formula. I overlooked it so many times. The formula is working now. User error...most definitely. Thank y'all for the help.

 

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

It's always like that. Some small thing that gets overlooked. 

 

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