Skip to main content
Participant
January 30, 2018
Answered

Conditional Calculation for Discount

  • January 30, 2018
  • 1 reply
  • 795 views

I have a form that is being used to register for exhibiting and sponsoring our conference. The user has the option to have a 10% discount applied to their cost if they exhibit at both conferences, but only if its both.

I need a calculation script that will apply the 10% discount if they select at least 2 of the 4 check boxes (spring member, fall member, spring non-member, fall non-member).

That amount needs to be placed in the discount box, so I can use its value to calculate the grand total. Below is my current setup of form fields.

Im not much of a scripter, so this kinda makes my head spin.

thanks for any insight you all may have as to how to make this work.

This topic has been closed for replies.
Correct answer try67

yes please, if there is no discount the full value of the total fees should be displayed so I can use that to add the vendor showcase fees to so that the total can be calculated.


Then use this code:

var checkboxes = ["exhibitSpringMem", "exhibitSpringNon", "exhibitFallMem", "exhibitFall"];

var totalChecked = 0;

for (var i in checkboxes) {

    var f = this.getField(checkboxes);

    if (f.valueAsString!="Off") totalChecked++;

}

var total = Number(this.getField("totalExhibitFee").value);

if (totalChecked<2) event.value = total;

else event.value = total*0.9;

Edit: Code fixed

1 reply

try67
Community Expert
Community Expert
January 30, 2018

What are the actual names of the checkboxes?

Also, do you want the "discount" field to show the value after the discount, or the discount itself?

In other words, if the total is 100, should it show 90 or 10?

Participant
January 30, 2018

exhibitSpringMem

exhibitSpringNon

exhibitFallMem

exhibitFallNon

Those are the 4 fields that they need to have selected at least 2 of to get discount.

For the display of the discount field, I would like it to show what the cost is after the discount.

thanks for your quick reply.

try67
Community Expert
Community Expert
January 30, 2018

Use this code as the custom calculation script of the discount field, then:

var checkboxes = ["exhibitSpringMem", "exhibitSpringNon", "exhibitFallMem", "exhibitFall"];

var totalChecked = 0;

for (var i in checkboxes) {

    var f = this.getField(checkboxes);

    if (f.valueAsString!="Off") totalChecked++;

}

if (totalChecked<2) event.value = "";

else {

    var total = Number(this.getField("totalExhibitFee").value);

    event.value = total*0.9;

}