2 Replies Latest reply on Feb 8, 2012 1:21 PM by josiahknight@gmail.com

    If/then JavaScript help needed

    josiahknight@gmail.com

      Hello,

       

      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 five fields as follows:

       

      A1 = a checkbox

      B1 = a field with a number value in it

      C1 = a field with a number value in it

      D1 = a field with a number value in it

      E1 = a field where the sum calculation will be.

       

      I want to write a script that will enter the sum of values of B1+C1+D1 into E1 if the checkbox in A1 is checked yes.

      If it is not checked yes, then it will enter the sum of values of B1+C1+ the value of D1 divided by 2 (and rounded down) into E1.

       

      Can anyone help??

       

      Thanks!

        • 1. Re: If/then JavaScript help needed
          George_Johnson MVP & Adobe Community Professional

          This should do it as the custom Calculate script for E1:

           

           

          // Custom calculate script
          (function () {
          
              // Get the field values, number fields as numbers
              var a1 = getField("A1").value;
              var b1 = +getField("B1").value;
              var c1 = +getField("C1").value;
              var d1 = +getField("D1").value;
          
              // Set this field (E1) value based on the state of the check box
              if (a1 === "Off") {
                  event.value = b1 + c1 + d1;
              } else {
                  event.value = b1 + c1 + Math.floor(d1 / 2);
              }
          
          })();
          
          • 2. Re: If/then JavaScript help needed
            josiahknight@gmail.com Level 1

            Great work and thanks for the quick feedback.

             

            The only thing that didn't work in the code was the checkbox Off status. When the checkbox was checked, it gave the wrong calculation.

             

            Easy fix: switch the 2 event value equations above and everything worked fine )

            1 person found this helpful