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

Javascript for subtraction

Contributor ,
Feb 26, 2024 Feb 26, 2024

Copy link to clipboard

Copied

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

Views

293

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Feb 26, 2024 Feb 26, 2024

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

Votes

Translate

Translate
Community Expert ,
Feb 26, 2024 Feb 26, 2024

Copy link to clipboard

Copied

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'

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

In SFN you need to escape space character with backslash.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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 = "";

}

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

What field names do you use?

Votes

Translate

Translate

Report

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