Skip to main content
Participant
Dec 16, 2019 9:32 PM UTC
Answered

In form calculator?

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 is closed to new replies. Start a new post to keep the conversation going.
Thom Parker
Thom ParkerCorrect answer
Community Expert
Dec 16, 2019 10:12 PM UTC

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

4 replies

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
Dec 16, 2019 10:12 PM UTC

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

 

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
DanJG85Author
Participant
Dec 17, 2019 5:05 PM UTC

That worked perfectly! Thank you so much!

Translate
DanJG85Author
Participant
Dec 17, 2019 6:08 PM UTC

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

Translate