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

dropdown list calculation with independent values

Explorer ,
Aug 19, 2020 Aug 19, 2020

Copy link to clipboard

Copied

Dropdown list1:

2 different doses of the same medication:

  • dose1
  • dose2

 

Dropdown list2:

3 different frequency of application of this medicine

  • every8hours (Q8h)
  • every6hours (Q6h)
  • every12hours (Q12h)

 

I would like to have a script to calculate the possibilities in one place on a pdf form:

  • dose1 (Q8h): meaning dose1 would be divided by 3 times per day
  • dose 1 (Q6h): meaning dose1 would be divided by 4 times per day
  • dose 1 (Q12h): meaning dose1 would be divided by 2 times per day

And the same for the dose2.

 

Thanks,

 

try67

I would appreciate your help in this.

Thanks,

 

 

 

TOPICS
Acrobat SDK and JavaScript

Views

824

Translate

Translate

Report

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

correct answers 1 Correct answer

Enthusiast , Aug 27, 2020 Aug 27, 2020

Give export value in dropdown1 dose1 100 and dose2 200, for dropdown2 give export value to Q6h 4, to Q8h 3, and to Q12h 2,  also select "commit value immediately in both fields.

In your text box enter this script:

event.value = this.getField("Dropdown1").value/this.getField("Dropdown2").value;
if(event.value == "NaN"||event.value == "Infinity"){
event.value = "";}

Votes

Translate

Translate
Enthusiast ,
Aug 22, 2020 Aug 22, 2020

Copy link to clipboard

Copied

can you be more specific. what are you actually try to calculate?

dose1 (Q8h): meaning dose1 would be divided by 3 times per day - how you want to calculate this?

Votes

Translate

Translate

Report

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
Explorer ,
Aug 22, 2020 Aug 22, 2020

Copy link to clipboard

Copied

dose 1 is 100 mg/kg/d

dose 2 is 200 mg/kg/d

This is the first drop list

 

second drop list has the options of the possible frequencies:

Q8h, Q6h, Q12h

and as you said: Q8h means I have to divide the dose by 3 (and by 4 for Q6h, and by 2 for Q12h)

Thanks,

 

 

Votes

Translate

Translate

Report

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 ,
Aug 22, 2020 Aug 22, 2020

Copy link to clipboard

Copied

HI,

 

This would appear to be a simple sum, or am I missing something:

 

if dose 1 is selected ( set export vaue to 100 ) and Q8h is selected (set export value  to 3).

 

then the result is just do a divide in the JavaScript, and add any additional information there.

 

Hope this helps

 

Malcolm

 

 

Votes

Translate

Translate

Report

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
Explorer ,
Aug 22, 2020 Aug 22, 2020

Copy link to clipboard

Copied

Yes Malcolm it is as you said but I wanted to know how the script should be written.

(NB: I am not an expert 🙂 )

Thanks,

Votes

Translate

Translate

Report

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 ,
Aug 22, 2020 Aug 22, 2020

Copy link to clipboard

Copied

You don't need a script just use simplified field notation and write like this: Dropdown1/Dropdown2

Unless you also want to show "200 mg/kg/d" in results? then you would need script.

Votes

Translate

Translate

Report

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 ,
Aug 22, 2020 Aug 22, 2020

Copy link to clipboard

Copied

Hi,

 

As above, would work but if you want the extra then you could use a calculation script ( I would only do this if your form does not have many fields as it can have a usability impact)

 

var doseCalc = this.getField("Dose").value / this.getField("Freq").value;
event.value = doseCalc + " mg/kg/d";

 

Hope that helps

 

Malcolm

Votes

Translate

Translate

Report

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 ,
Aug 22, 2020 Aug 22, 2020

Copy link to clipboard

Copied

That would work but He/She also need to use format or He/She will get really large number if for example divide 100/3.
so use simplified field notation and add this in "Format->Custom format->Custom format script:
AFNumber_Format(2, 0, 0, 0, " mg/kg/d", false);
number 2 represent decimals so set to whatever number you want.

Votes

Translate

Translate

Report

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
Explorer ,
Aug 22, 2020 Aug 22, 2020

Copy link to clipboard

Copied

This would not work because I can't divide by the frequency itself, this is why i though it will need a script with condition:

if from droplist1 the dose is 100, and from droplist2 the frequency is 8 then the result is: 33.3 mg

(100/3)

 

(droplist1:

-dose 1 is 100 mg/kg/d

-dose 2 is 200 mg/kg/d

 droplist2 has 3 frequencies:

-Q8h,

-Q6h,

-Q12h)

Votes

Translate

Translate

Report

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
Enthusiast ,
Aug 22, 2020 Aug 22, 2020

Copy link to clipboard

Copied

So what exactly do you want? if it's 33.3 you want to show it as 33?

Votes

Translate

Translate

Report

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
Explorer ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

Dropdown list1:

2 different doses of the same medication:

  • dose1
  • dose2

 

Dropdown list2:

3 different frequency of application of this medicine

  • every8hours (Q8h)
  • every6hours (Q6h)
  • every12hours (Q12h)

 

I would like to have a script to calculate the possibilities in one place on a pdf form:

  • dose1 (Q8h): meaning dose1 would be divided by 3 times per day
  • dose 1 (Q6h): meaning dose1 would be divided by 4 times per day
  • dose 1 (Q12h): meaning dose1 would be divided by 2 times per day

And the same for the dose2.

 

Thanks,

 

Votes

Translate

Translate

Report

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
Enthusiast ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

Can you show us example how you have imagine this calculation pls?

 

Votes

Translate

Translate

Report

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
Explorer ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

If I put it in a sentence it would be:

if drop1=dose1 and drop2=Q8h

then event value= dose1/ 3

and 

if drop1=dose2 and drop2=Q12h

then event value= dose2/ 2

etc...

Votes

Translate

Translate

Report

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
Enthusiast ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

  1. Sry for all the questions, just want to make sure what you want. So for example:dose1/dose2 would be 100/3 = 33.33 ? Why not use simplified field notation? Unless you need something else? 

Votes

Translate

Translate

Report

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
Explorer ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

Thanks Asim for trying to help me.

If I can get the script for the following sentence, regardless what they are representing as numbers or doses this will fix my problem:

 

if drop1=choice A and drop2=Q8h

then event value= choice A/ 3

and 

if drop1=B and drop2=Q12h

then event value= B/ 2

Votes

Translate

Translate

Report

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
Enthusiast ,
Aug 27, 2020 Aug 27, 2020

Copy link to clipboard

Copied

LATEST

Give export value in dropdown1 dose1 100 and dose2 200, for dropdown2 give export value to Q6h 4, to Q8h 3, and to Q12h 2,  also select "commit value immediately in both fields.

In your text box enter this script:

event.value = this.getField("Dropdown1").value/this.getField("Dropdown2").value;
if(event.value == "NaN"||event.value == "Infinity"){
event.value = "";}

Votes

Translate

Translate

Report

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