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

FormCalc or JavaScript "IF" calculation

skemp50
Registered: Jun 20 2007
Posts: 10

Could someone give me the proper syntax in either FormCalc or JavaScript for the following calculation to be entered in a "Text3" form field:

If Text1 minus Text2 is less than or equal to "0", display "0" in Text3.
If Text1 minus Text2 is greater than "0", display the result of (Text1 -Text2) in Text3.

I've tried and tried, but I can't get any variation to work.

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Right now I do not have LiveCycle Designer available to me, but I would try:

if (Text1 - Text2 < 0) then 0
else Text1 - Text2
endif

George Kaiser

Dripto
Registered: Jun 20 2007
Posts: 47
I doubt the above will work. Try this in FormCalc. Click on the Text3 text box and use the calculate event. Type in the following

if ((Text1.rawValue - Text2.rawValue) <= 0)
this.rawValue = "0"
else this.rawValue = (Text1.rawValue - Text2.rawValue)

Check to see if it works in PDF preview.
skemp50
Registered: Jun 20 2007
Posts: 10
My thanks to gkaiseril and Dripto---both your suggestions work great in LiveCycle. I was using the "calculate" property of a text box in a form created in Acrobat 8.0. According to everything I read, both FormCalc and JavaScript should work in Acrobat, but it didn't work for me.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
For those interested, my suggestion used the FormCalc syntax and Dripto's suggestion used the JavaScript syntax. LiveCycle Designer automatically detects the syntax and chooses the scripting language accordingly.

George Kaiser