Copy link to clipboard
Copied
Hello, I'm fairly new to javascript and have never used it within Adobe Acrobat before so I'm pretty lost. I'm using Acrobat Pro DC and I'm trying to take the user input from two text fields and add them together to show the sum in a third text field. What I have set up is three text fields with the names of "valueOne", "valueTwo", and "sum".
In the actions tab on the properties window for the valueOne field I have a trigger of Mouse Down and the action to run javascript, I wrote -
var firstValue = this.getField("valueOne").value;
I did the same on the second text field with -
var secondValue = this.getField("valueTwo").value;
Then for the third text field, which will show the sum, I'm not sure how to autofill it? I've tried something like -
event.value = (this.getField("valueOne + valueTwo").value=="") ? "";
It's not working - and I'm not sure how to have it just show up without using a trigger event?
Any advice would be much appreciated, thank you!
There are no guarantees it will work on a mobile device. If the built-in Sum command didn't work, it's not likely that a script will, either.
For best results on an iPad I recommend using PDF Expert by Readdle, although it's not free.
The code to use is:
var firstValue = this.getField("valueOne").valueAsString;
var secondValue = this.getField("valueTwo").valueAsString;
if (firstValue=="" || secondValue=="") event.value = "";
else event.value = Number(firstValue) + Number(secondValue);
Copy link to clipboard
Copied
Do you want the sum field to be empty if one (or both) of the other fields is empty?
Copy link to clipboard
Copied
Yes. I'm also trying to get it to work on mobile devices. I found out a way to set it up by going to the calculate tab and having the sum field be the sum of the two other fields, and that works well, however when I test it on an iPhone 6 the sum is not appearing even after I enter two values into the other fields.
Copy link to clipboard
Copied
There are no guarantees it will work on a mobile device. If the built-in Sum command didn't work, it's not likely that a script will, either.
For best results on an iPad I recommend using PDF Expert by Readdle, although it's not free.
The code to use is:
var firstValue = this.getField("valueOne").valueAsString;
var secondValue = this.getField("valueTwo").valueAsString;
if (firstValue=="" || secondValue=="") event.value = "";
else event.value = Number(firstValue) + Number(secondValue);