1 Reply Latest reply on Mar 6, 2015 2:05 PM by gkaiseril

    Nested if statements

    Sean.twyman Level 1

      I have a form with 2 test field And I am a trying to calculate the value of one field based on the contents of the other 2 fields. I am tring to use nested if statements and I cant seem to get them to work..


      Here is my code.

      var sb = this.getField("Sub Total");
      var cn = this.getField("Customer#");
      var sh = this.getField("Shipping");
      if (sb.value < "250.00") {
          if (cn.startsWith("CA" || "UT" || "CO")) {
              sh.value = '$9.00';
          } else {
              sh.value = '$11.00';
      } else {
          sh.value = '$0.00';
        • 1. Re: Nested if statements
          gkaiseril MVP & Adobe Community Professional

          Why are you testing numeric values as strings with non-numeric characters in them?


          What is the "startsWith" method? I do not believe this is available in Acrobat's JavaScript. The JavaScript documentation at MDN states it is experimental and not available in all variations of JavaScript. It also possilbe provides code to create the prototype.


          Have you looked at the JavaScript console to see your code has any errors?


          You can list field values to the JavaScript console to see what the actual value is within a JavaScript.


          Assuming you have formatted the numeric fields as Number, with 2 decimal places and the '$" currency symbol:


          // custom calculation for the target field;

          var sb = this.getField("Sub Total");
          var cn = this.getField("Customer#");


          event.value = 0; // assumed default shipping value;
          if (sb.value < 250) {
          event.value = 11; // assumed default shipping cost below 250.
              if (cn.value.toUpperCase().substr(0,2) == "CA" || cn.value.toUpperCase().substr(0,2) == "UT" || cn.value.toUpperCase().substr(0,2) == "CO") {
                  event.value = 9;



          What is displayed as formatted value is not always what the actual value of the field is.