Skip to main content
Participant
December 16, 2019
Answered

In form calculator?

  • December 16, 2019
  • 1 reply
  • 1661 views

Ahoy all! So I will start by saying I am brand new to javascript and am learning things the hard way! 🙂

 

I am trying to figure out a way that I can have two text fields, Field1 & Field2, and have it so that when a number is entered into Field2 it will automatically add it to Field1 then clear itself out.

 

Example: Field1 has a value of 10, when I enter 10 into Field2 then Field1 become 20 and Field2 becomes blank. I am figuring the javascript will have to be attached to a button but my co-pilot, google, is letting me down on this one. Any ideas? Thank you!

This topic has been closed for replies.
Correct answer Thom Parker

The script doesn't have to be on a button, unless that's what you want.

 

But here is a button script.

this.getField("Field1").value += Number(this.getField("Field2").value);

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

 

Field 1 needs to be defaulted to 0

 

 

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
December 16, 2019

The script doesn't have to be on a button, unless that's what you want.

 

But here is a button script.

this.getField("Field1").value += Number(this.getField("Field2").value);

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

 

Field 1 needs to be defaulted to 0

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
DanJG85Author
Participant
December 17, 2019

That worked perfectly! Thank you so much!

DanJG85Author
Participant
December 17, 2019

Would it be possible to multiple the value of Field2 by -1 to convert it to a negative value?