These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Add a Subtract Calculation into a Text field

jodie7111
Registered: May 22 2007
Posts: 9

Help!
I can only seem to add the existing calculations, can someone give me the formula for subtracting one total from another? Or is there any other way of doing this?
I have 2 text fields, which are totals, and i want to then subtract one from the other.

Thanks

fluidcom
Registered: Feb 28 2006
Posts: 4
var a = this.getField("your1stFieldName").value;
var b = this.getField("your2ndFieldName").value;
event.value = a.value - b.value;


Sincerely,

David Lindblad
PDF INSYNC

www.fixmypdf.com
jodie7111
Registered: May 22 2007
Posts: 9
Thanks, but it still doesn't work

My fields are called EstimateTotal and ActualTotal and i want to subtract ActualTotal from Estimatetotal.

i have typed this:

var a = this.getField(EstimateTotal).value;
var b = this.getField(ActualTotal).value;
event.value = a.value - b.value;

Does it go in Simplified Field Notation or Custom Calculation Script?

Thanks
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Your code should read and go in the "Custom calculation script" box:

var a = this.getField("EstimateTotal").value; // variable for the estimated value
var b = this.getField("ActualTotal").value; // variable for the actual value
event.value = a - b; // compute difference of the two values

or:

var a = this.getField("EstimateTotal"); // variable for the estimated field object
var b = this.getField("ActualTotal").value; // variable for the actual field object
event.value = a - b; // compute difference of the two objects values

or:

// compute the difference of the estimated value less the actual value
event.value = this.getField("EstimateTotal").value - this.getField("ActualTotal").value;

The quotes around the field name indicate the sting name assigned to the field. JavaScript is an object language, so one need to identify an object and then use a method or property of that object for the task at hand.

For the "Simplified calculation" box the code would be:

EstimateTotal - ActualTotal

George Kaiser

jodie7111
Registered: May 22 2007
Posts: 9
Brilliant thanks, it works!
anhchec
Registered: Feb 23 2009
Posts: 5
Please help!!!!
I did as what you said but it didn't work.

var a = this.getField("fieldname1").value;
var b = this.getField("fieldname2").value;
var c = this.getField("fieldname3").value;
event.value = a - b - c;

fieldname2 is a multiplication of fieldname1 and another text filed
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Quote:
I did as what you said but it didn't work.
Where did you place this code? What event of what field?

Do you get any errors? If this is a calculation script for the field, does the field display a value? If so, what is it?

Have you confirmed that the field calculation order is correct?

George
anhchec
Registered: Feb 23 2009
Posts: 5
Thank you so much for answering me!!!!
I have tried again and find what the mistake was. But I have another question. I hope you could help me.
I have to make a multiplication of text field which is percentage figure and another text file.
For example:
I have one file like this:
(_percent_) %............................... // (for example percent here is 10%)
Cash: $ (_number_)...........
Total: $ (_percent x number_).........
The formula (_percent x number_) will understand that percent is like a number (10, not 10%). I have to type the percent number is 0.01 :((
Do you know the formula to do this operation????
bstory
Registered: Nov 15 2007
Posts: 6
Can I use numerical values in Simplified Field Notation? I just want to have the field calcuation value be the product of two other fields divided by 100.

I have tried:

(RegPay1.0*Base%1.0)/100

but it doesn't work.

The reason I want to do this is I don't want users of the forms to have to type in a percentage as a decimal. I want the calculated field to deal with that.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Are you getting any errors in the JavaScript Debugging console?

The fields used in this type of computation also need to be simple names (no spaces, no dots, no special symbols, etc).

George Kaiser

bstory
Registered: Nov 15 2007
Posts: 6
No, but I got something in the field - maybe a NaN or something.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
"NaN" stands for "Not a Number".

When I build a form with your calcuation, I receive the following error:
Quote:
missing ) in parenthetical
1:Field:Calculate
I can get the following "Simplified field notation" script to work:
(RegPay * Base) / 100

George Kaiser

Kathleen Kearns
Registered: Jan 9 2009
Posts: 8
Hi,

I'm struggling with setting up a subtraction field. Tried the above suggestions and none of them are working. What am I doing wrong?

7dayoveralltotal minus CashAdvancesubtract
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Johnathan,

The 'minus' or 'subtraction' operator is '-'.

So for the 'Simplified field notaion':
7dayoveralltotal - CashAdvancesubtract
Assuming your field names are '7dayoveralltotal' and 'CashAdvancesubtract'

George Kaiser

Kathleen Kearns
Registered: Jan 9 2009
Posts: 8
Hi, thank you for the response. It worked. Now I'll have to figure out why my profile show's "jonathon" :)
stackett
Registered: Jul 16 2010
Posts: 1
I have an equation that is 5 entries and then a total, but I need them to have the option of adding or subtracting. So it would be for example: _ +/- _ +/- _+/- _ +/- _ +/- = ? Does that make sense? Can you help me? Thanks!!