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

Calculate discount

tgaspard
Registered: Aug 17 2011
Posts: 15

I am preparing a form for our office and need to add in a section that allows for various standard discounts to be applied to the subtotal before taxes are added.
 
I've found a few examples on this forum, but they are from quite a few years ago and clearly for old versions of this program or something because they dont work.
 
I have a hidden field where i combine all of the various/applicable subtotals and 3 checkboxes for the discount rates (20, 50, 100). Obviously, if no discount is checked, the value of the discount box would be 0.
 
I've tried using an IF Then script to calculate the discount and had no success.
 
Any help would be appreciated.

-tina

My Product Information:
LiveCycle Designer, Windows
maxwyss
Registered: Jul 25 2006
Posts: 255
Why don't you just try the "old" examples? The principles have not changed. The only thing which has changed is the way you get your fields on the form (that changed with Acrobat 9 and the (please insert your own words here) form edit mode.

Now, for something which should work: Make sure that your checkboxes have the same field name. Then assign the return values according to your discount (such as 0.2, 0.5, 1). In the field where you run the calculation for your form (probably the Grand Total) you then add the following piece of code:

this.getField("discount").value = this.getField("subtotal").value * (this.getField("discountrate").value.toString().replace(/Off/g,"0")*1) ;

that's one long line, where the discount in currency (field "discount") is calculated from the subtotal before discount (field "subtotal") and the group of checkboxes (field "discountrate").

As simple as it can be.

The reason why we have to do the replace() is to get the correct value for "unchecked", which is always "Off" for checkboxes (and radiobuttons).

Hope this can help.

Max Wyss.

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Is this a LiveCycle form, or an Acrobat form?

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

tgaspard
Registered: Aug 17 2011
Posts: 15
I got it working. Thanks!

-tina