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

Calculating a 'product (x)' with a % as a value

JR27
Registered: Jul 16 2007
Posts: 6

I'm trying to make an order form and I'd like to make it fill in some of the fields automatically by a calculation. Basically, there are 3 fields, 2 of them are just dollar amounts, the 3rd is a discount. I can have it multiply all 3, but only by putting the opposite percentage as the discount can I get the correct result (like, if I wanted a 20% discount, I would need to put in 80%). Does anyone know of a custom script that can account for this so that it will display the correct discount percentage while also giving a correct end product?

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
It sounds like you are using Acrobat and not LiveCycle Designer.

Assuming you have the following named 3 fields:

"SubTotal" = the subtotal of the purchases, numeric with 2 decimal places
"DiscoutRate" = the discount % percent to apply, percent with 0 decimal places
"DiscountAmount" = the "DiscountRate" times the 'SubTotal", numeric with 2 decimal places.

For the "DiscountAmount" field, you can use the following "Custom calculation script:

// compute the discount amount based on the discount rate
event.value = this.getField("DiscoutRate").value * this.getField("SubTotal").value;
// suppress a zero result
if (event.value == 0) event.value = "";

George Kaiser

JR27
Registered: Jul 16 2007
Posts: 6
Thank you for trying to help. I tried the script, but I can't seem to get the result I was looking for, it still gives me the opposite result (in example, say the value of the fields are "quantity" 2 times "price" $500 to get a value of $1000 in a "SubTotal" field marked as hidden, then applying that subtotal field to the script you gave me, "SubTotal" of $1000 times "DiscountAmount" of 40% [0.4] still results in a product of $400, when the result I need would be $600 [or 40% off of $1000]). Note: the version of Acrobat I have is 7.0 Professional in case that has an affect. Any further help would be greatly appreciated.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You have the amount of the discount, now just subtract the discount amount from the subtotal. If yoy do not want to disclose the discount amount:

// compute the discount amount based on the discount rate
event.value = ( 1- this.getField("DiscoutRate").value) * this.getField("SubTotal").value;
// suppress a zero result
if (event.value == 0) event.value = "";

Online

George Kaiser

JR27
Registered: Jul 16 2007
Posts: 6
Works great, thanks very much for your help =)