Skip to main content
Participant
September 26, 2022
Answered

Calculation depending on drop down list item selected

  • September 26, 2022
  • 1 reply
  • 3905 views

Hi There,

 

Would somebody be able to provide some assistance with a calculation, please? I'm not familiar with Javascript and I suspect this is what is required.

 

I have a dropdown list on a form which I have created in Adobe Acrobat Pro. I would like to run different calculations depending on which item is selected from the list.

Some of the items on the dropdown list will need to be calculated per week and shown as a monthly value, whilst others will be simply QTY* Unit=cost.

 

My calculation to get the monthly value for a weekly charged product works, which is QTY* Units*52.1429/12. This gives me the monthly cost for a product that is charged weekly, which is great.

 

However, I need to specify that this calculation should only be applied if the weekly product was selected from the dropdown list.

 

My basic logic would be:

if (Dropdown list item="weekly product") then execute QTY* Units*52.1429/12

else execute QTY* Units.

 

I hope I've explained this clearly enough.

 

Many Thanks,

 

Simon

 

 

 

 

This topic has been closed for replies.
Correct answer Nesa Nurani

If you use this as custom calculation script in field where you want to show result of calculations, use something like this:

var qty = Number(this.getField("QTY").valueAsString);
var unit = Number(this.getField("Unit").valueAsString);
if(this.getField("Name of dropdown field goes here").valueAsString == "weekly product")
event.value = qty*unit*52.1429/12;
else
event.value = qty*unit;

 

This is just a basic script.

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
September 26, 2022

If you use this as custom calculation script in field where you want to show result of calculations, use something like this:

var qty = Number(this.getField("QTY").valueAsString);
var unit = Number(this.getField("Unit").valueAsString);
if(this.getField("Name of dropdown field goes here").valueAsString == "weekly product")
event.value = qty*unit*52.1429/12;
else
event.value = qty*unit;

 

This is just a basic script.

Participant
September 26, 2022

Hi Nesa,

 

That worked perfectly.

 

Thank you for your quick reply, much appreciated 🙂

Participant
October 5, 2022

Hi Nesa,

Quick question.

 

If I wanted to use this method to calculate 2 fields that are both weekly, what separator would I need to use to declare both for the calculation?

 

var qty = Number(this.getField("QTY").valueAsString);
var unit = Number(this.getField("Unit").valueAsString);
if(this.getField("Name of dropdown field goes here").valueAsString == "weekly product1" AND "weekly product2")
event.value = qty*unit*52.1429/12;
else
event.value = qty*unit;

 

I'm not sure how to add both into the declaration, I'm thinking like I'm in SQL.

 

Many Thanks,

 

Simon