2 Replies Latest reply on Aug 21, 2015 9:11 AM by try67

    JavaScript Calculation in PDF

    ashh.allen

      I am trying to create a calculation that allows my customers to calculate their cost. (Sounds simple...but I am new to JavaScript so I am struggling to fix it)

       

      Objective: I want the formula to calculate the customer's total price based on their membership status/price options plus any add-ons. So the total will either reflect a "NonMember" price with add-ons, a "Member" price with add-ons, or a "Brokerage" price with add-ons.

       

      Water prices:

      NonMember = $3.50

      Member = $3.00

      Brokerage = $1.75

       

      Add-ons:

      Water 30amp Extensions= $100

      Water 50amp Extensions= $120

       

      here is what I have so far. I based it on a different formula with only two variables that I used for a different calculation:

       

      (function () {

       

          var nNonMember = +getField("Water_NonMember").value;

          var nMember = +getField("Water_Member").value;

          var nBrokerage = +getField("Water_Brokerage").value;

       

          var v1 = ( nNonMember * 3.50 )  + ( +getField("Water_30amp").value * 100 )  + ( +getField("Water_50amp").value * 120 );

          var v2 = ( nMember * 3.00 )  + ( +getField("Water_30amp").value * 100 )  + ( +getField("Water_50amp").value * 120 );

          var v3 = ( nBrokerage * 1.75 )  + ( +getField("Water_30amp").value * 100 )  + ( +getField("Water_50amp").value * 120 );

        

      event.value = nNonMember > 0 ? v1 : v2;

       

      })();

       

       

      Im guessing the problem is the "event.value" (or the whole formula)..... I cant seem to figure it out.


      So I need the calculation to work so that: Only one option can be selected between Member and NonMember, but that selection can work in conjunction with Brokerage. So they can have both Member and Brokerage, NonMember and Brokerage, or any of the 3 options alone, but can never input a value for both Member and NonMember.

       

      am I missing something?