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

Add the value of two text fields to appear in a third text field.

Engaged ,
Jun 27, 2018 Jun 27, 2018

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!

TOPICS
Acrobat SDK and JavaScript

Views

1.7K

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 , Jun 27, 2018 Jun 27, 2018

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);

Votes

Translate

Translate
Community Expert ,
Jun 27, 2018 Jun 27, 2018

Copy link to clipboard

Copied

Do you want the sum field to be empty if one (or both) of the other fields is empty?

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
Engaged ,
Jun 27, 2018 Jun 27, 2018

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.

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 ,
Jun 27, 2018 Jun 27, 2018

Copy link to clipboard

Copied

LATEST

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);

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