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

Calculation using if statement

LT2010
Registered: Jul 2 2010
Posts: 3

Hi,

I am new using PDF calculation and I am wonder how do I get the QTY amount to calculate a shipping with different rate using if statement. Any help will be appreciated and thank you in advance.

IF QTY equal 1 THAN the shipping price will be $1.50
IF QTY equal 2-10 THAN the shipping price will be $6.50
IF QTY equal 11-25 THAN the shipping price will be $8.50
IF QTY equal 26-75 THAN the shipping price will be $10.00
IF QTY equal 76-100 THAN the shipping price will be $12.50

Thank you,
LT

My Product Information:
Acrobat Pro 9.3.1, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Try looking around the forums a bit. Similar scripts and links to reference files have been posted in many places. For example: http://www.acrobatusers.com/forums/aucbb/viewtopic.php?id=26722

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

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Are you using Acrobat crated forms or LiveCycle Designer created forms?

The 2 programs are capable of creating forms but the language to script in each product is different and not interchangeable.

If you used Acrobat, see [url=http://www.acrobatusers.com/tutorials/conditional-execution]Conditional Execution[/url] by Thom Parker

Besides the 'if' statement JavaScript also has the 'switch' statement, which may be clearer as to what is going on and can be easier to maintain if the values of the comparison change.

Assuming you are using Acrobat forms, the quantity field name is 'QTY' and the calculation is the custom JavaScript calculation is for the shipping cost field:
// using the value of the QTY fieldvar nQty = this.getField('QTY').valueswitch(true) {// take the following action when the case value is met// quantity is 0case (nQty == 0)event.value = '';break; // quantity is 1case (nQty == 1) :event.value = 1.5;break; // quantity is between 2 and 10case (nQty >= 2 and nQty =< 10):event.value = 6.5;break; // quantity is between 11 and 25case (nQty >= 11 and nQty =< 25):event.value = 8.5;break; // quantity is between 26 and 75case (nQty >= 26 and nQty =< 75):event.value = 10;break; // quantity is between 76 and 100case (nQty >= 76 and nQty =< 100):event.value = 12.5;break; // quantity is over 100default:var sMsg = 'Quantity ordered is over 100 items\n';sMsg += 'Please contact customer service at 1-800-555-1212\n'sMsg += 'for the shipping cost.\n\n'sMsg += 'Thank You';app.alert(sMsg, 2, 0);event.value = '';break;} // end of determining shipping cost

George Kaiser

SUnger
Registered: Mar 21 2011
Posts: 1
I am new to the JavaScript writing. I am trying to create an if calculation on a form that I have. The Staement is If Line 12 is greater that line 15, enter the difference. Would sure appreciate some help.

Thanks

Steve