16 Replies Latest reply on Jun 6, 2017 4:21 PM by nrodri

    Calculate sales tax from different fields based on text field Seller Type (If Else Statement)

    nrodri Level 1

      Hello java community!

      I have been researching for days like crazy and breaking my brain without any resolution to this. I am fairly new to javascript so I am hoping someone can help me.


      Field names and values

      Seller Type: "Individual", "Commercial"

      Province: "AB", "SK", "YK", etc - each of the provinces have their appropriate tax rate as export value e.g. "AB" is 5, "SK" is 10 etc.

      Sales Tax: based on the export value of the province selected.

      Subtotal: sum of amounts


      Trying to achieve this calculation:

      If (SellerType="Commercial") then Subtotal*(SalesTax/100)


      if (SellerType="Individual") then 0


      My code right now is:

      var st = getField("SellerType").value;

      var tax = getField("SalesTax").value;

      var sub = getField("Subtotal").value;

      if (st==="Commercial"){

      event.value = sub.value*(tax.value/100);

      } else {

      event.value = 0



      I am about to give up, please help!!!

      Thank you in advance