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

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

New Here ,
Apr 11, 2019 Apr 11, 2019

Copy link to clipboard

Copied

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

Views

312

Likes

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

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

Would this help Malcolm?

Likes

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

Copy link to clipboard

Copied

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

Likes

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

Copy link to clipboard

Copied

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";

}

Likes

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

Copy link to clipboard

Copied

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

scripting error.JPG

Likes

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

Copy link to clipboard

Copied

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

Likes

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