1 Reply Latest reply on Oct 16, 2012 1:34 PM by gkaiseril

    show/hide fields with percents

    kharris85

      I'm trying to find a script to show/hide a field depending on the percentage thats in one of the fields. The script that I usually use for just basic numbers is:

       

      var r1 = this.getField("V1");
      var r2 = this.getField("V2");

       

      r1.hidden = true;
      r2.hidden = true;

       

      if(event.value <= "100")
      {
      event.willCommit = true;
      {

      r1.hidden = false;
      }
      }

       

      if(event.value >= "101")

      {

      event.willCommit = true;

      {

      r2.hidden = false;

      }

      }

       

      So I need basically the same thing again except I need it to be field one appears if "38.00%" or higher is entered. If anything lower then that is entered I need field 2 to show up..I just can't seem to get it to work once the decimal points are in there.

       

      Thank you in advance for your help!

        • 1. Re: show/hide fields with percents
          gkaiseril MVP & Adobe Community Professional

          The percentage format is just for display and rounds the actual field value, the actual field value is the decimal number created by the division or entered by the user.

           

          100% is entered as 1.00 but if a result of a computation it could be 99.5 - 1.4. So if you want to compare the computed value you may need to round the fields value to the same number of decimal places as the display field. You should be aware that using the Math.round method of JavaScript can cause a rounding error with floating point numbers. You can use the util.printf method in Acrobat JavaScript to correctly round a field value.

           

          I also would not use quotation marks on numeric constants.

           

          var r1 = this.getField("V1");
          var r2 = this.getField("V2");
          r1.hidden = true;
          r2.hidden = true;

          if(util.printf("%,1 .2f", event.value) <= 1.00) {
          r1.hidden = false;
          }

          if(util.printf("%,1 .2f", event.value) >= 1.01) {
          r2.hidden = false;
          }