7 Replies Latest reply on Nov 29, 2017 11:21 AM by George_Johnson

# How do I calculate the difference between two numbers in text fields  Hi, I am fairly new to this and I'm quite certain that I'm going to be embarrassed by how simple the answer is

I am doing a simple calculation...total assets - total liabilities = Net worth

I have my total assets and my total liabilities working, but there is not a subtract option in the text field properties for the Net worth field.

I do not know any Java script...can anyone help me out?

Thanks

Judy

• ###### 1. Re: How do I calculate the difference between two numbers in text fields  You can use the simplified field notation option, but first your input field names have to be changed so they do not contain any spaces or punctuation. For example:

TotalAssets - TotalLiabilities

If you want to use JavaScript, which will be required if you ever get into more complicated calculations, you can use something like the following as the fields custom Calculate script (Net worth):

(function () {

// Get field values as numbers

var v1 = +getField("total assets").value;

var v2 = +getField("total liabilities").value;

// calculate this field value

event.value = v1 - v2;

})();

There are no restrictions on field names when using JavaScript.

• ###### 2. Re: How do I calculate the difference between two numbers in text fields  Thank you so much George, it works perfectly!

Have a great day!

Judy

• ###### 3. Re: How do I calculate the difference between two numbers in text fields  Good Morning George,

I used the script you posted in this forum and it worked fantastic but the value it returns is either positive or negative depending on the two cells I'm using.  Can this be modified so the result only returns a positive number? Then I would be able to complete other calculations.

• ###### 4. Re: How do I calculate the difference between two numbers in text fields  And what should it show if the result is actually negative, then?

• ###### 5. Re: How do I calculate the difference between two numbers in text fields  If you mean that you want to determine the absolute value of the difference, then just change the last line to:

event.value = Math.abs(v1 - v2);

• ###### 6. Re: How do I calculate the difference between two numbers in text fields

Okay, for some reason that did not work for me.

My input is like this:

(function () {

// Get field values as numbers

var v1 = +getField("Text178.0").value;

var v2 = +getField("Text178.1.0").value;

// calculate this field value

event.value = v1 - v2;

})();

The values are 25 for Text178.0 and 57 for Text178.1.0 so I would expect my answer to be -32. I am getting 0 (zero).

Also, out of curiosity, why would Adobe NOT add something so simple as a subtract function under calculate?

Thanks!

• ###### 7. Re: How do I calculate the difference between two numbers in text fields  Check for errors in the JavaScript console by pressing Ctrl + J.