Skip to main content
Nikolaos.
Inspiring
February 26, 2024
Answered

Javascript for subtraction

  • February 26, 2024
  • 2 replies
  • 1671 views

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?

This topic has been closed for replies.
Correct answer try67

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

}


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

2 replies

Bernd Alheit
Community Expert
Community Expert
February 26, 2024

What field names do you use?

Eric Dumas
Community Expert
Community Expert
February 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'
  •  

  • 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 

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

  • enter your calculation
  • Click on Close
  • At the top right f the screen toggle between Preview and Close to test your 'function'
Nesa Nurani
Community Expert
Community Expert
February 26, 2024

In SFN you need to escape space character with backslash.