3 Replies Latest reply on Apr 16, 2015 1:49 AM by Luutiuno

    JavaScript calculation event If... statement help

    Luutiuno

      Using Adobe Acrobat Pro XI, I created a fillable form and need help with a calculation event.  I believe I need a nested if statement and have been testing with this.getField - I need help.  The fields involved are [PageCount] and [Weight].  I need the script to look at the number in the [PageCount] field, compare it to a weight scale (below) and enter the corresponding value in the [Weight] field.   The scale is as follows:

       

      1-20 pages = each error is 5 points, or 5

      21-40 pages = 4

      41-70 pages = 3

      71-100 pages = 2

      >100 pages = 1

       

      The [Weight] field will be hidden on the form and will then be multiplied by a [Total_Errors] field.

       

      Any assistance will be greatly appreciated.  Thank you.

        • 1. Re: JavaScript calculation event If... statement help
          try67 MVP & Adobe Community Professional

          Use something like this as the custom calculation script of the "Weight" field:

           

          var pageCount = Number(this.getField("PageCount").value);
          if (pageCount>=1 && pageCount<=20) event.value = 5;
          else if (pageCount>=21 && pageCount<=40) event.value = 4;
          else if (pageCount>=41 && pageCount<=70) event.value = 3;
          else if (pageCount>=71 && pageCount<=100) event.value = 2;
          else if (pageCount>=101) event.value = 1;
          else event.value = 0;
          
          • 2. Re: JavaScript calculation event If... statement help
            brittanys203048

            I have a similar problem, I tried to edit this code for mine and I cant get it to calculate.  Not getting any errors...

             

            If the number the client enters in Methadone is between 1-10 I want the multiply by 4 and display result in MethadoneMed

            If the number the client enters in Methadone is between 11-20 I want to multiple by 5 and display result in MethadoneMed

             

            here is what I have

             

             

            var MethadoneMed = Number(this.getField("Methadone").value); 

             

            if (Methadone>=1 && Methadone<=10) event.value = this.getField("Methadone").value*(4); 

             

            else if (Methadone>=11 && Methadone<=20) event.value = this.getField("Methadone").value*(5); 

             

            else event.value = 0; 

             

             

            any ideas?

             

            • 3. Re: JavaScript calculation event If... statement help
              Luutiuno Level 1

              Many, many thanks!  The code works beautifully!  At first, the result was a checkmark and I freaked out a bit.  Then figured out I needed to change the font and format of the cell.  Again, your help is much appreciated.