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

Javascript error

RP
Registered: Sep 11 2009
Posts: 8
Answered

I'm trying to create a simple javascript calculation in a PDF form but I'm getting a "missing ; before statement 1: at line 2".

In this particular field, the first Ice Skating poster is free but each one after it costs $20. There is a quantity and total field, this calculation is for the total.

Var a=getField("IceSkating").value;
event.value = a * 20 (-20)
if (event.value < 0) event.value = 0

If anyone can see my error please reply.

Thanks

My Product Information:
Acrobat Pro 8.1.6, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2399
The parenthesis need be be around both parts of the equation. Try this instead:
(a*20)-20

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
The keyword for variable is 'var' and not 'Var'. One uses parenthesis to set the order of calculation so you need to put a mathematical or operator between parenthesis.

So you code could read:

event.value = (a * 20) + (-20);

But any of the following will also work:

event.value = a * 20 - 20;

event.value = (a * 20) - 20;

event.value = (a * 20) - (20);

George Kaiser

RP
Registered: Sep 11 2009
Posts: 8
Thanks for your advise.

Based on your suggestions, this is the script I ended up using:

var a = getField("IceSkating").value;
event.value = (a * 20) -20;
if (event.value < 0) event.value = 0Works perfect.

Thanks!