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

If calculation

dianar08
Registered: Feb 17 2010
Posts: 4

I cannot get my if, else if calculation to work. I have tried everything. I created a purchase order form and if they choose a certain quantity the price will be x, but no matter what i do it will not produce a number, here is the code:

if(Quantity[0]=250)then
UnitPrice[0]=1.65
else
(Quantity[0]== 500) then
UnitPrice[0] 1.40
endif

I did not write any variables before the if calculation and I am using javascript.

can anyone help?

My Product Information:
Acrobat Pro 8.1.7, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Your syntax is all wrong. It looks like you're trying to write code in Visual Basic. Acrobat only accepts JavaScript.

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

dianar08
Registered: Feb 17 2010
Posts: 4
I have the form created, I cannot get my "if, else if" calculation to work.
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi dianar08,

This tutorial on writing if statements in JavaScript (the scripting language Acrobat uses) should be helpful-
http://www.acrobatusers.com/tutorials/conditional-execution

Hope this helps,

Dimitri
WindJack Solutions
www.pdfscripting.com
www.windjack.com
krickett47
Registered: Feb 4 2010
Posts: 18
I have the following calculation that doesn't work after exiting the form and returning:

this.getField("201").value = this.getField("200").value / this.getField("213").value;

201 is formated as a percentage
200 is formated to a number
213 is formatted to sum two nubmers

When I exit the form and go back in to enter 0 in the number fields the percentage calculation does not work anymore, and I get formatting error messages. Can you help?
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If the value of field 213 is ever 0, then you have a problem. You have to catch this situation and deal with it before it becomes a problem. How you deal with it depends on what a value of 0 means in the context of the form.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

javascript_gumby
Registered: Mar 29 2010
Posts: 2
Hi there

I'm having great difficulty with a calculation. I've downloaded javascript resources from the above mentioned sites, but nothing has addressed the issue I have.

I have a form where individual items cost $3.50, but if the buyer wants multiples of 3, the price is then $10. So if they want 4 items the price will be $13.50 etc.

Any advice would be greatly appreciated.
Many thanks

I is a javascript gumby!

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Have you looked at the documentation for Mozilla [url=https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference]JavaScript 1.5 Reference[/url], from which Acrobat JavaScirpt is an extension and subset of.

You can use the modulo operator and "Math.floor()" method to obtain the multiples of 3 items purchased and the number of items in excess of a multiple of 3 items.

George Kaiser

javascript_gumby
Registered: Mar 29 2010
Posts: 2
Thanks gkaiseril, I'll have a look there, and see what I can find (and create) :O)

I is a javascript gumby!