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

Javascript code for calculate two numbers after press a button

Guest
Mar 23, 2020 Mar 23, 2020
Hello! Can someone please help me?
 
What I'm looking for are two Javascript codes, for two different buttons, where basically they will do just that:
GIFVida.gif
There will be a button for Addition and another for Subtraction.
Both buttons will take the value you write in the field in the middle of them, and perform the chosen calculation, thus showing the result in the field beside.
 
In the GIF, the value you entered to perform the calculation is deleted after you click on any of the buttons. Addition will never exceed the Max field. And subtraction will never pass 0.
It would be really cool if that were possible too, but if it's a problem, you don't have to.
 
Thank you very much!
TOPICS
How to , PDF forms
1.7K
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 ,
Mar 23, 2020 Mar 23, 2020

This is pretty simple. 

Here's the add script:

 

this.getField("Current").value  +=  this.getField("Middle").value;

this.getField("Current").value  = "";

 

Use an if statement to set the limits.

Read this article:

https://www.acrobatusers.com/tutorials/conditional-execution/

 

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 ,
Mar 23, 2020 Mar 23, 2020

This is pretty simple. 

Here's the add script:

 

this.getField("Current").value  +=  this.getField("Middle").value;

this.getField("Current").value  = "";

 

Use an if statement to set the limits.

Read this article:

https://www.acrobatusers.com/tutorials/conditional-execution/

 

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
Guest
Mar 24, 2020 Mar 24, 2020
LATEST

Thank you!

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