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

Javascript for subtraction

Contributor ,
Feb 26, 2024 Feb 26, 2024

In Excel I would do it like this:

= (total vacation - vacation already taken) - requested vacation

How can I write this into a text field in javascript?

TOPICS
Create PDFs , How to , JavaScript
1.2K
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 ,
Feb 26, 2024 Feb 26, 2024

If this is a calculation script replace this.getField("Ergebnisfeld").value = ... with event.value = ... .

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 ,
Feb 26, 2024 Feb 26, 2024

Hi,

It is quite straight forward.

  • Open the document you are working on
  • At the top of your screen, click on the Tools tab
  • Type 'form' in the search field
  • in the results, click on 'Create form'
  • EricDumas_1-1708947372655.png

     

  • your opened document should be visible, or get it from your scanner or start a new one
  • Clcik on start to detect fields, 
  • Create the fields you need 

EricDumas_2-1708947445123.png

  • Make sure to name the fields in a logical/meaningful way
  • In the Properties of the last one (to display result of the calculation)

EricDumas_0-1708947193237.png

  • enter your calculation
  • Click on Close
  • At the top right f the screen toggle between Preview and Close to test your 'function'
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 ,
Feb 26, 2024 Feb 26, 2024

In SFN you need to escape space character with backslash.

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
Contributor ,
Feb 26, 2024 Feb 26, 2024

As far as I've been able to try it, it doesn't work.

Is it possible for you to send me the exact code that I need to insert to accomplish a subtraction?

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
Contributor ,
Feb 26, 2024 Feb 26, 2024

Thank you for this step-by-step description, very helpful.

But after several attempts I can say that it doesn't work.

It doesn't do subtraction.

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
Contributor ,
Feb 26, 2024 Feb 26, 2024

I also tried it with GPT, here is the code. Thanks everyone for your help.

 

var fieldValue1 = parseFloat(this.getField("Textfeld1").value);

var fieldValue2 = parseFloat(this.getField("Textfeld2").value);

var fieldValue3 = parseFloat(this.getField("Textfeld3").value);

if (!isNaN(fieldValue1) && !isNaN(fieldValue2) && !isNaN(fieldValue3)) {

    var result = fieldValue1 - fieldValue2 - fieldValue3;

    this.getField("Ergebnisfeld").value = result;

} else {

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

}

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 ,
Feb 26, 2024 Feb 26, 2024

If this is a calculation script replace this.getField("Ergebnisfeld").value = ... with event.value = ... .

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 ,
Feb 27, 2024 Feb 27, 2024

I am very surprised. As you can see from the screenshots, the calculation works. Can you explain (with screenshots) what does not work for 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
New Here ,
Apr 10, 2024 Apr 10, 2024

I'm having the same issue. My fields are SUBTOTALA and SUBTOTALB

In the Simplified Field Notation box, I type:

SUBTOTALA-SUBTOTALB

Acrobat acts like it's going to calculate, the formula "blips" in the box, then the radio box goes back to no calculation. The same thing happens when I type

SUBTOTALA - SUBTOTALB

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 ,
Apr 11, 2024 Apr 11, 2024

Radio-button fields do not have a Calculate tab... Where exactly are you applying this code?

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
New Here ,
Apr 11, 2024 Apr 11, 2024
LATEST

Well, I did the EXACT SAME CODE in the EXACT SAME PLACE today and it worked perfectly. I saved quickly, thanked my lucky stars and went on my merry way!

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 ,
Feb 26, 2024 Feb 26, 2024

What field names do you use?

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