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

Engaged ,
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!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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

TOPICS
Acrobat SDK and JavaScript

Views

361

Likes

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

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

Engaged ,
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!

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

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

TOPICS
Acrobat SDK and JavaScript

Views

362

Likes

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
Jun 27, 2018 0
Most Valuable Participant ,
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?

Likes

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
Reply
Loading...
Jun 27, 2018 0
Engaged ,
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.

Likes

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
Reply
Loading...
Jun 27, 2018 0
Most Valuable Participant ,
Jun 27, 2018

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

Likes

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
Reply
Loading...
Jun 27, 2018 1