Skip to main content
Participant
April 12, 2019
Question

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

  • April 12, 2019
  • 2 replies
  • 616 views

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

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
April 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";

}

Participant
April 15, 2019

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

try67
Community Expert
Community Expert
April 15, 2019

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

BarlaeDC
Community Expert
Community Expert
April 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

Participant
April 12, 2019

Would this help Malcolm?