Copy link to clipboard
Copied
I am trying to figure out how to write a custom calculation script for a discount on an order form.
There are several items on the order form (all $16.60 each).
I add all the items and multiply them by 16.60 for the TOTAL.
If the TOTAL is greater than $398.40 (= 24 items), then I want to give a new total that takes 5% off the total.
Can someone please help me create that formula? I have no idea how to make these javascript formulas. Thank you!!!
Copy link to clipboard
Copied
I probably would not just change the total without indicating why the total is no longer a multiple of $16.60 - I would have a filed called "SubTotal" (which is the total before the discount), and then another field in which I would calculate the discount, and then the new "Total" field that is the SubTotal - Discount.
In the Discount field, you can use something like this as your calculation script:
var subTotal = this.getField("SubTotal").value;
event.value = 0; // the default for this field
if (subTotal > 398.40) {
event.value = (subTotal * 0.05).toFixed(2);
}
The script for "Total" would then be this:
event.value = this.getField("SubTotal").value - this.getField("Discount").value;
Copy link to clipboard
Copied
Can you help me understand which field to put this first calculation script?
I have a field for:
total qty items
subtotal (qty*16.60)
and total (event.value = this.getField("SubTotal").value - this.getField("Discount").value; )
Copy link to clipboard
Copied
As I said, this would be an additional field called "Discount". So in in addition to the "Total" and "SubTotal" fields you mention, you would need to add a third field called "Discount" and use the script from above.
Copy link to clipboard
Copied
If you really want do this with just one Total field, use this:
event.value = Number(this.getField("Text1").value) + Number(this.getField("Text2").value) +
Number(this.getField("Text3").value) + Number(this.getField("Text4").value); // keep on going until you have all your input fields
if (event.value > 398.40) {
event.value = (event.value * 0.95).toFixed(2);
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now