
1. Re: How can I put a mathematically if  formula in a field of a pdf  form?
try67 Nov 22, 2013 3:45 AM (in response to kbNetCom)1 person found this helpfulThis is easily done. You just use the builtin Sum function under the Calculate tab, and then enter this code as the custom validation script:
(For the positive only fields)
if (Number(event.value)<0) event.value = "";
(For the negative only fields)
if (Number(event.value)>0) event.value = "";
The total fields can also be implemented with the builtin Sum function...

2. Re: How can I put a mathematically if  formula in a field of a pdf  form?
kbNetCom Nov 22, 2013 4:09 AM (in response to try67)Hi Gilad,
thanks a lot for the quick reply.
But .. I think, I have not expressed correctly, what I need.
there are 7 Fields in a row  and in Field 1 and 2 numbers have to be put in  and field 1 and 2 have to be added  and if this result is positiv it has to be displayed in field 3 and if negative in field 4.
How can I define field 1 and 2, that they have to be added .. and  do I have to mark the code with a start and end sign??

3. Re: How can I put a mathematically if  formula in a field of a pdf  form?
try67 Nov 22, 2013 5:53 AM (in response to kbNetCom)I understood the situation, but let me give you some more detailed advice. So you set the following setting as the Calculate option for fields 3 AND 4:
For "Field 3" you use the following as the custom Validation script:
And for "Field 4" you use this as the custom Validation script:
The results are:
You can find the file here:
https://files.acrobat.com/preview/c00025e08bfb46d79ac9300e87578333

4. Re: How can I put a mathematically if  formula in a field of a pdf  form?
kbNetCom Nov 22, 2013 6:41 AM (in response to try67)Really good :) !!!
Thank you very much.
Is it the same, when I want to subtract Field 2 from Field 1? There is no subtraction in the calculation ????

5. Re: How can I put a mathematically if  formula in a field of a pdf  form?
gkaiseril Nov 22, 2013 9:14 AM (in response to kbNetCom)1 person found this helpfulYou will have to use the simplified field notation or a custom JavaScript calculation to perform subtraction or division. If there is any chance of a zero divisor then one needs to use a custom JavaScript calculation.
As to your specific example, because the field names have a space within their name you need to either use a special character in the simplified field notation or a custom JavaScript calculation.
Simplified field notation requires use of the JavaScript escape character to proceed the space or other white space/special character.
Field\ 1  Field\ 2
Custom JavaScript calculation:
event.value = this.getField("Field 1").value  this.getField("Field 2").value;

6. Re: How can I put a mathematically if  formula in a field of a pdf  form?
kbNetCom Nov 25, 2013 1:23 AM (in response to gkaiseril)!! Thank you GKaiseril,
this works! :)
Now I tried to combine the subtraction with the if  formula, but somehow I get a syntax error ... even after trying nearly every possibility  I cannot find out, what is wrong
Please have a look to what I did ...
if((event.value=this.getField("Anzahl_berechnet_01").valuethis.getField("Anzahl_erhalten_ 01").value)<0;"";event.value=this.getField("Anzahl_berechnet_01").valuethis.getField("Anz ahl_erhalten_01").value)
Thanks in advance !!!

7. Re: How can I put a mathematically if  formula in a field of a pdf  form?
Test Screen Name Nov 25, 2013 2:32 AM (in response to kbNetCom)1 person found this helpfulYou have at the end a close parenthesis (bracket) which belongs at the end of the if condition, not the end of the statement. Look at the form in reply#1.

8. Re: How can I put a mathematically if  formula in a field of a pdf  form?
kbNetCom Nov 25, 2013 7:47 AM (in response to Test Screen Name)Hello together,
thanks again for all yóur help.
Everything is very helpful and works at all!!
Nevertheless I have anexpected results ... ;).
In fields with calculation field1+field2 the result is not always correct f.e. 6070=5 and 2 fields right it calculates 10*5=350€.
In fact I am worried !! (and a little bit confused).
Is there anybody who has experienced the same ...????
Do you know, how to change this miscalculating?
Thanks again in advance ..... !!

9. Re: How can I put a mathematically if  formula in a field of a pdf  form?
Test Screen Name Nov 25, 2013 8:23 AM (in response to kbNetCom)1 person found this helpfulJavaScript calculations do have some surprises, especially with big numbers and fractions. People working with money often find it is much harder than they expected. But small whole numbers is something JavaScript does well.
If you seem to see that 6070 isn't 10 and 10*5 isn't 50, then first look at the formatting of the result fields. And look for other JavaScript and calculations which may be left in that affect these fields. If that doesn't help, please post your final code. Please use copy/paste, every detail matters.

10. Re: How can I put a mathematically if  formula in a field of a pdf  form?
gkaiseril Nov 25, 2013 9:33 AM (in response to kbNetCom)It sounds like some of the calculations are one step behind. You may need to correct the field calculation order.

11. Re: How can I put a mathematically if  formula in a field of a pdf  form?
kbNetCom Nov 26, 2013 5:59 AM (in response to gkaiseril)Good Morning,
I tried several things to solve the calculation problems.
At last I am quite sure, that the problem is, that our trainee, who had to make the formular, has built the fields and the layout in EXCEL and then imported to Acrobat.
When I made all fields manually in Acrobat, all the calculations and formulas you proposed to me, worked well and fine. Right now I think, my problems are solved. I will come back to tell you  probably tomorrow.
So ... thank you very much.

12. Re: How can I put a mathematically if  formula in a field of a pdf  form?
kbNetCom Dec 1, 2013 11:37 PM (in response to kbNetCom)Good morning all together,
I hope you enjoyed your weekend!?
All the things you told me in your answers above are working fine  so far !THANK YOU!.
Now I need to know, if I can select from several rows all the items which are positiv or all items which are negativ ...
For a better understanding: in the formular are 20 rows which calculate if things are delivered or not. If not delivered and on the bill  it would be a value which has to be subtracted. The other way around, if there are goods which are delevered, but not on the bill, we have to add the price for it  positive numbers !
I hope there is a function for this  otherwise it is a very uncomfortable if .. function.
Thanks in advance.
Klaus