18 Replies Latest reply: Apr 25, 2012 12:07 PM by DanFlamma1 RSS

    Formula to divide three field entries (D=A/B/C)

    Phillips99 Community Member

      I have a formula to obtain a value and it involves dividing three field entries. I don't know enough about javascript to correctly enter the code to make this happen. I have 20 rows in a form and I need to calculate column D. I saw a thread on how to divide two fields but I need to go further with that. Can anyone help me? I've added what I was working from (left) and what I tried to develop (right).

       

       

      InternetPersonal

      // establish variables for the field names for the dividend and divisor.

      var sDividend = 'My Dividend Field Name';

      var sDivisor = 'My Divisor Field Name';

       

      // get the value of the divisor field

      var nDivisor = this.getField(sDivisor).value;

      // get the value of the dividend field

      var nDividend = this.getField('sDividend').vlalue;

       

      // do not change the code below this line

      // clear the result field value

      event.value = '';

      // see if we have a non-zero divisor

      if (nDivisor != 0) {

         // we can now divide

         event.value = nDividend / nDivisor;

      } // end division calculation

       

      The above assumes your are dividing the values of 2 fields.

      // Assigning the variables

      var PW1 = "PlotWt1";

      var WBC1 = "WetbuConversion1";

      var AF1 = "Acre Factor1";

       

      // Getting the values

      var nPW1 = this.getField(PW1).value;

      var nWBC1 = this.getField(WBC1).value;

      var nAF1 = this.getField(AF1).value;

       

      // clear the result field value

      event.value="";

      // see if we have a non-zero divisor

      if (nWBC1 !=0) {

          //Actual division operation

          event.value = nPW1 / nWBC1 / nAF1;

      }// end of division calculation