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

Javascript For Totals Days x Length (Drop Down Menu Options)

New Here ,
Apr 11, 2019 Apr 11, 2019

HELP! I'm new to javascipting and need to create a form for work:

We need to charge boaters a fee depending on the number of days staying (docking) and the boats berthage (length).

I have a field that creates the total days from two drop down calendars currently. I also have have a field with a drop down selection of the boats length.

However, I have no idea how to combined the two though?

Here's what I need to calculate/charge from the two fields:

If boat is staying less then 30 days I need to charge $20/day

If boat is <18m  AND is staying longer then 30 days they are charged $260/month

If boat is between 18-20m AND they are staying longer then 30 days charged $280/month

Please help :S

TOPICS
Acrobat SDK and JavaScript , Windows
649
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 ,
Apr 12, 2019 Apr 12, 2019

HI,

Are you able to share the document via a sharing platform, so that we can provide help based on how you created your form, as there are many ways to achieve this?

Regards

Malcolm

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
New Here ,
Apr 12, 2019 Apr 12, 2019

Would this help Malcolm?

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
New Here ,
Apr 12, 2019 Apr 12, 2019

Heres the charges I need to charge based on the boat length (berthage)

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 ,
Apr 12, 2019 Apr 12, 2019

You can use this code as the custom calculation script of your field (you'll probably need to adjust the field names in the first two lines, to match the actual ones in your file):

var stayDuration = Number(this.getField("StayDuration").valueAsString);

var boatLength = Number(this.getField("BoatLength").valueAsString);

if (stayDuration==0 || boatLength==0) event.value = "";

else if (stayDuration<30) event.value = "$20/day";

else {

    if (boatLength<18) event.value = "$260/month";

    else event.value = "$280/month";

}

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
New Here ,
Apr 14, 2019 Apr 14, 2019

I get an error when I try and create this scripting?

scripting error.JPG

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 ,
Apr 15, 2019 Apr 15, 2019
LATEST

In the future post your code as text, not an image.

I can see an error in the screenshot, though. You're missing an operator between

TotalDays==0

and

Length==0

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