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.
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.