8 Replies Latest reply on Jan 6, 2010 10:23 AM by gkaiseril

# Script to calculate the discount amount..

Hi, I need a script to calculate the following;

Package Weekly Amount = £100

Package Discount Percentage field = 10%

Package Discount Weekly Amount = -£10

Subtotal = £90

The script I have does not work and my knowledge of javascript is limited.

My script:

var a = this.getField("Weekly Amount");
var b = this.getField("Package Discount");
event.value = a.value - (a.value * (b.value/100));

Any help with this would be appreciated.

• ###### 1. Re: Script to calculate the discount amount..

What do you mean by "does not work"? Do you get an error, or just the wrong

result? If the latter, which result are you getting?

• ###### 2. Re: Script to calculate the discount amount..

Apologies for being vague..!

What the script is doing is returning a value based on £100 initial cost then applying a 10% discount as -£900.

When I need it (or another script) to return -£10.

Sorry for any confusion.

Thanks

• ###### 3. Re: Script to calculate the discount amount..

What's the actual value of both fields? Is the percentage actually 10, or is

it 0.1 (as Acrobat usually treats percentage fields)?

You can check by adding this to your script (after the first two lines):

app.alert("Weekly Amount is: " + a.value);

app.alert("Package Discount is: " + b.value);

Also, you can post the file to the forum.

• ###### 4. Re: Script to calculate the discount amount..

Yes the percentage field shows as 10% and the value of the Weekly Amount field is £100.

I am unable to post the form, sorry.

Thanks

• ###### 5. Re: Script to calculate the discount amount..

So the discount is -1 * a * (b/100)

• ###### 6. Re: Script to calculate the discount amount..

So would the revised script look like this;

var a = this.getField("Weekly Amount");
var b = this.getField("Package Discount");
event.value = a.value - (-1 * a.value * (b.value/100));

If so that does not calculate the discount as I need it to.!

Thanks

• ###### 7. Re: Script to calculate the discount amount..

There must be something wrong with the value of the fields.