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

Custom calculation javascript for complicated form

Community Beginner ,
Dec 05, 2016 Dec 05, 2016

Hello,

I have a booking form with some complicated calculations that requires 'if' and 'then' custom javascript.

The form offers tickets at $350 per person, up to 16 people, with up to 4 additional tickets for $100 each. I tried some script from a previous form but I just don't know how to customise the script to take the initial 16 tickets into account, and then any additional number of tickets after that.

var numTix = Number(this.getField("QTY1").value);

if (numTix==0) event.value = 0;

else if (numTix==1) event.value=350;

else event.value = 350+((numTix-1)*100);

Any suggestions would be very greatly appreciated.

Thanks,

Kate

TOPICS
Acrobat SDK and JavaScript
862
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 ,
Dec 06, 2016 Dec 06, 2016

I don't quite follow... What's the price per ticket up to 16, and what's the price after that?

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 Beginner ,
Dec 07, 2016 Dec 07, 2016

Hi try67,

The ticket price is $300 up to 16 and then $100 after that (but only an additional four tickets can be bought at the $100 price mark). So you can effectively purchase 20 tickets in total for $5,200

Thanks so much.

Kate

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 ,
Dec 07, 2016 Dec 07, 2016

And what if the user enters a number bigger than 20 into the number of tickets field? Or did you apply a validation that prevents that?

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 Beginner ,
Dec 07, 2016 Dec 07, 2016

Oh I hadn't got that far, but I will now. Thanks for reminding me

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 ,
Dec 07, 2016 Dec 07, 2016

OK, well the code will be something like this:

var numTix = Number(this.getField("QTY1").value);

if (numTix<=16) event.value=300*numTix;

else event.value  = (16 * 300) + ((numTix-16)*100);

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 Beginner ,
Dec 07, 2016 Dec 07, 2016
LATEST

Thank you so very very much! That's fantastic try67, works perfectly. You really saved my bacon

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
LEGEND ,
Dec 07, 2016 Dec 07, 2016

Also, if it's possible for the user to specify a number greater than 20, less than 0, or a non-integer, what should happen? If you're using a dropdown that limits the possible values to 1 through 20, please ignore this question.

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