Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Calculation depending on drop down list item selected

Community Beginner ,
Sep 26, 2022 Sep 26, 2022

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

 

 

 

 

TOPICS
PDF forms
4.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Sep 26, 2022 Sep 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.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2022 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 26, 2022 Sep 26, 2022

Hi Nesa,

 

That worked perfectly.

 

Thank you for your quick reply, much appreciated 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 05, 2022 Oct 05, 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

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 05, 2022 Oct 05, 2022

For 'AND' use &&

For 'OR' use ||

EDIT:

Just to add if it's value from same field then you need to use OR, like this:

if(this.getField("Name of dropdown field goes here").valueAsString == "weekly product1" || this.getField("Name of dropdown field goes here").valueAsString =="weekly product2")

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 05, 2022 Oct 05, 2022

Thank you Nesa, that worked perfectly.

 

Really appreciate your help.

 

Simon

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 03, 2023 Aug 03, 2023
LATEST

Hello Nesa

Im trying something very similar, but its not working with me. I have a dropdown with 13 products. 4 of those products cost $550/hr for labor and travel the rest cost $495/hr Here is my script but keeps saying that qty2 is not defined. Im not versed on java script so not sure why this is happening. Q9 is my qty box for labor and Q10 is qty for travel. The idea is that if I select product A, then multiplies Q9 * 550 and Q10 * 550 if its Product B then it Q9*495 and Q10*495

var qty = Number(this.getField("Q9").value);
var qty2 = Number(this.getField("Q10").value);
var sys = Number(this.getField("System").valueAsString);
var laborL = 550;
var travelL = 550;
var laborS = 495;
var travelS = 495;
if(this.getField("System").valueAsString == "EX500"||this.getField("System").valueAsString == "FS200"||this.getField("System").valueAsString == "TOPOLYZER"||this.getField("System").valueAsString == "LenSx");
event.value = qty * laborL;
event.value = qty2 * travelL;
else
event.value = qty * laborS;
event.value = qty2 * travelS;

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines