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

Conditional calculations in Acroabt DC Form

New Here ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

Good morning,

Firt of all, sorry for my Eglish.
I ask the experts if there is a solution to this problem.
I have to prepare a form with Adobe Acrobat DC with conditional calculations, but I don't know Java Script.

 

The problem
This is a km reimbursement form that must satisfy the following 3 conditions:
1) You are traveling alone. The calculation in this case is: the first 200 km at € 0.29. The others at € 0.14
2) You are traveling with 1 person. The calculation in this case is: the outward journey (half of the total km) at € 0.29. The return to € 0.14
3) You are traveling with 2 people. The calculation in this case is: the total of km at € 0.29

 

I have prepared the form with the following fields:
• 3 selection keys: "Choice 1", "Choice 2", "Choice 3" self-excluding
• 1 "km1" field that must be filled in by the user
• 1 “euro3” field which must contain the result of the calculation

 

Technical questions:
1) In the “Custom calculation script” of the “euro3” field can I insert the three conditions (similar to Basic Language type “IF” “THEN”)?
2) Otherwise I have to create 3 result fields (“euro 3” in the case of “Choice1”, “euro 3BIS” in the case of “Choice2”, “euro 3TRIS” in the case of “Choice3”)?

Thank you
Francesco

TOPICS
PDF forms

Views

966

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 ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

Not sure if I understand it right but try put this code in "euro3" field as custom calculation script:

var ch = this.getField("Group1").valueAsString;
var km = Number(this.getField("km1").value);

if(ch == "Choice1" && km > 200){
event.value = 58+((km-200)*.14);}
else if(ch == "Choice1" || ch == "Choice3"){
event.value = (km*.29);}
else if(ch == "Choice2"){
event.value = km/2*.43;}

 

I'm assuming you are using 3 radio buttons (named "Group1") so change name in script  if needed.

 

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
New Here ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

Thanks Nesa. It doesn't seem to work. I certainly make some mistakes. I keep looking for my mistake and will let you know

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 ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

Like I said, perhaps I didn't understand it right. Can you tell me what doesn't work?

here is an example file I made, take a look at it and see if thats what you looking for

https://drive.google.com/uc?export=download&id=1a-sxBj1q8Lh02ep7pkvB6EcMY-lAPuYK 

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
New Here ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

You are great. I copied / pasted the strings from your pdf, replaced the field names and magically everything works. You are really great. Thanks thanks 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
New Here ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

Nesa, there is only one small thing: try to type less than 200 km: you will see that in choice 2 (if you are traveling with 1 person) the amount changes. It must be the same for all choices. 

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 ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

From what you write I assume it's e.g. 300km, 150km is 0.29 and other 150km is 0.14.

What calculation should be for that part?

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
New Here ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

Sorry... Under 200 is all at ,29

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 ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

So it's same as Choice1?

In that case use this:

var ch = this.getField("Group1").valueAsString;
var km = Number(this.getField("km1").value);

if((ch == "Choice1" || ch == "Choice2") && km > 200){
event.value = 58+((km-200)*.14);}
else if(ch == "Choice1" || ch == "Choice2" || ch == "Choice3"){
event.value = (km*.29);}

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
New Here ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

Nesa, I don't want to take advantage of you. You've already done a great job for me. In your last string you solved the problem of calculating "<200km" but now in the calculation "> 200km", choice 1 (travel alone) is equal to choice 2 (travel with 1 person). This should be: half a, 29 and half a, 14. Thank you so much for your speed, your skill and your patience.

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 ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

Thats ok, my english also isn't the best so sometimes I'm having problems understanding questions.

Can you please just write prices for choice2 so we avoid confusion.

choice2 ->

price for under 200km = ?

price for over 200km = ?

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
New Here ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

Great.

 

So:

 

price for under 200km = all at 0.29

 

price for over 200km = Choice 1 (travel alone): firts 200 km at 0.29; the rest at 0.14. Ex: 300km: 200 at .029 and 100 at 0.14

Choice 2 (travel with 1 person): half at 0.29; half at 0.14. Ex: 300km: 150 at .029 and 150 at 0.14

Choice 3 (travel with 2 persons): all at 0.29 (the same as under 200km)

Thank you very much Nesa

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 ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

Yes, thats what I used in my first code, take a look under code for choice 2 it says km/2*.43

300km. 150km * .29 = 43.5 ,150km * .14 = 21,  300km =  64.50

except I used .29+.14 =.43 so I used 300/2*.43 = 64.50

Try calculating again with first 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 ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

Sorry I think I got it now, if Choice2 is under 200km then it's .29 and if it's over 200 then it's half-half.

Try with this code:

var ch = this.getField("Group1").valueAsString;
var km = Number(this.getField("km1").value);

if(ch == "Choice1" && km > 200){
event.value = 58+((km-200)*.14);}
else if(ch == "Choice1" || ch == "Choice3"){
event.value = (km*.29);}
else if(ch == "Choice2" && km > 200){
event.value = km/2*.43;}
else if(ch = "Choice2"){
event.value = km*.29;}

 

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
New Here ,
Feb 14, 2021 Feb 14, 2021

Copy link to clipboard

Copied

LATEST

Great Grea Great Nesa, All is working good now. You are a very special person.

Thank You very, very much.

I'm a graphic designer: if you need something from me please do not hesitate.

Francesco

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