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

conditional calculation from drop down menu

fiat154
Registered: Feb 11 2008
Posts: 3

Hi this is my first post, I hope someone can help.

I am using Acrobat 8 Pro.
I have a form with 4 fields:
Item
No of Units
Unit Cost
Amount

The field 'Item' is a drop down menu with 2 options: Showerheads & Toilets.
In layman terms this is what I want to achieve:

Quote:

If the item selected is a Showerhead and its Unit Cost is greater than or equal to $60 then the Amount equals $30 x No of Units.

Else If the item selected is a Showerhead and its Unit Cost is less than $60 then the Amount equals (Unit Cost/2) x No of Units.

Else If the item selected is Toilets and its Unit Cost is greater than or equal to $300 then the Amount equals $150 x No of Units.

Else If the item selected is Toilets and its Unit Cost is greater than or equal to $300 then the Amount equals (Unit Cost/2) x No of Units.

At the moment to do this I have a Custom Calculation script on the 'Amount' field which looks like this:

Quote:

var units1 = this.getField("units1").value
var unitCost = this.getField("Unitcost1").value
var Item1 = this.getField("Item1").value
var Amount1 = this.getField("Amount1")

if (Item1 = "Showerheads" && unitCost > "59")
{Amount1.value = "30" * units1}
else if (Item1 = "Showerheads" && unitCost < "60")
{Amount1.value = (unitCost / 2) * units1}
else if (Item1 = "Toilets" && unitCost > "299")
{Amount1.value = "150" * units1}
else if (Item1 = "Toilets" && unitCost < "300")
{Amount1.value = (unitCost / 2) * units1}

This is kind of working but seems to not refresh itself when the Item changes even though I have Commit Immediately ticked on for the 'Item' field.

I have 8 lines that I need to do this for, so if anyone has any ideas at all I would be forever grateful.

thanks in advance.

My Product Information:
Acrobat Pro 8.1.1, Macintosh
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If this script is in the Calculation Event for "Amount1" then it has an error. Do not apply the calculation result to the field directly, instead use "event.value". You also should not quote numerical values

For example:
if (Item1 = "Showerheads" && unitCost > 59)
{
event.value = 30 * units1
}

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

fiat154
Registered: Feb 11 2008
Posts: 3
thanks thomp.

so now I have:

Quote:
var units1 = this.getField("units1").value
var unitCost = this.getField("Unitcost1").value
var Item1 = this.getField("Item1").value

if (Item1 = "Showerheads" && unitCost > 59)
{
event.value = 30 * units1
}

else if (Item1 = "Showerheads" && unitCost < 60)
{
event.value = (unitCost / 2) * units1
}

else if (Item1 = "Toilets" && unitCost > 299)
{
event.value = 150 * units1
}

else if (Item1 = "Toilets" && unitCost < 300)
{
event.value = (unitCost / 2) * units1
}
Which does work for when 'Showerheads' is selected in 'Item1' but if you change it to 'Toilets' it keeps the conditional statements for 'Showerheads' ie. still not refreshing the calculation even though i have Commit Immediately on for the 'Item1' field.

any other thoughts?

thanks again.