3 Replies Latest reply on Feb 10, 2012 11:36 AM by George_Johnson

    Math.min JavaScript help needed




      I am trying to write a script for a fillable PDF in Adobe Acrobat, but I don't have much experience with JavaScript and I need some help!


      Basically I have three fields as follows:


      A1 = a field with a number value in it

      B1 = a field with a number value in it

      C1 = a field where the sum calculation will be.


      I want to write a script that will enter the lesser of the values in A1 and B1 into C1. If no value has been entered into B1, then it enters the value of A1 into C1.


      This is what I have come up with so far:

          // Get the field values, number fields as numbers

          var d1 = getField("A1").value;

          var d2 = +getField("B1").value;


          // Set the field value to either A1 or B1, whichever is lesser

           event.value = Math.min(d1,d2);


      Some of the problems with the script so far are:

      1. It does not calculate correctly if there is no value entered in B1 (should give just A1).
      2. It doesn't update the event.value if A1 is changed (until another form field is modified)


      Can anyone help??