6 Replies Latest reply on Aug 2, 2011 12:18 PM by mlhend9

    Need Help with Javascript for Acrobat Pro 9

    mlhend9

      Hello,

      I am creating a PDF form in Adobe Acrobat Profession 9.  Not having a lot of experience with Javascript, I have found this forum very helpful and have used many of the script examples for other issues I have had.  I was hoping someone could help with the following script, I have tried many variations, cannot get it to work.

       

      var ratio = this.getField("ratio").value
      var concentration = this.getField("concentration").value
      var result = this.getField("result").value
      if(ratio.value>=50.00)
      {result.value ='PASS';}
      if(ratio.value".value>=40.00)
      {result.value ='PASS';}
      if((concentration.value ==61) && (ratio.value >= 49.25))
      {result.value ='PASS';}
      if((concentration.value ==61) && (ratio.value >= 39.25))
      {result.value ='PASS';}
      if((concentration.value ==62) && (ratio.value >= 48.50))
      {result.value ='PASS';}
      if((concentration.value ==62) && (ratio.value >= 38.50))
      {result.value ='PASS';}
      else
      {result.value = 'FAIL';}

      This is just a piece of the code  The concentration values run from 61 through 99 and the ratio value varies for each concentration value, there is a high ratio and a low ratio.  The result of this field with populate the results field with a PASS or FAIL.  This is not working......any help is greatly appreciated!

        • 1. Re: Need Help with Javascript for Acrobat Pro 9
          George_Johnson MVP & Adobe Community Professional

          Try changing this line:

           

          var result = this.getField("result").value

           

          to this:

           

          // Get a reference to the result field

          var result = this.getField("result");

          1 person found this helpful
          • 2. Re: Need Help with Javascript for Acrobat Pro 9
            George_Johnson MVP & Adobe Community Professional

            Actually, you need to do the same to the other similar statements at the beginning of the script.

            1 person found this helpful
            • 3. Re: Need Help with Javascript for Acrobat Pro 9
              mlhend9 Level 1

              Thanks George.  I updated the script to:

               

              // Get a reference to the result field

              var ratio = this.getField("ratio");

              // Get a reference to the result field

              var concentration = this.getField("concentration");

              // Get a reference to the result field

              var result = this.getField("result");

              if(ratio.value>=50.00)

              {result.value ='PASS';}

              if(ratio.value >=40.00)

              {result.value ='PASS';}

              if((concentration.value ==61) && (ratio.value >= 49.25))

              {result.value ='PASS';}

              if((concentration.value ==61) && (ratio.value >= 39.25))

              {result.value ='PASS';}

              if((concentration.value ==62) && (ratio.value >= 48.50))

              {result.value ='PASS';}

              if((concentration.value ==62) && (ratio.value >= 38.50))

              {result.value ='PASS';}

              else

              {result.value = 'FAIL';}

               

              However, I am still getting a FAIL result even when the ratio is 50.00 or equal to the passable ratio.

               

               

              • 4. Re: Need Help with Javascript for Acrobat Pro 9
                mlhend9 Level 1

                I just corrected the first part of the script to the below.  Still only produces a FAIL result

                 

                // Get a reference to the ratio field

                var ratio = this.getField("ratio");

                // Get a reference to the concentration field

                var concentration = this.getField("concentration");

                // Get a reference to the result field

                var result = this.getField("result");

                if(ratio.value>=50.00)

                {result.value ='PASS';}

                if(ratio.value >=40.00)

                {result.value ='PASS';}

                if((concentration.value ==61) && (ratio.value >= 49.25))

                {result.value ='PASS';}

                if((concentration.value ==61) && (ratio.value >= 39.25))

                {result.value ='PASS';}

                if((concentration.value ==62) && (ratio.value >= 48.50))

                {result.value ='PASS';}

                if((concentration.value ==62) && (ratio.value >= 38.50))

                {result.value ='PASS';}

                else

                {result.value = 'FAIL';}

                 

                • 5. Re: Need Help with Javascript for Acrobat Pro 9
                  George_Johnson MVP & Adobe Community Professional

                  If this script is attached to the Calculate event of the "result" field, if I understand the logicm the code should be something like:

                   

                  // Get a reference to the ratio field
                  var ratio = this.getField("ratio");
                  
                  // Get a reference to the concentration field
                  var concentration = this.getField("concentration"); 
                  
                  // Default
                  var res = "FAIL";
                  
                  if (ratio.value >= 40.00) {
                      res = 'PASS';
                  }
                  
                  if ((concentration.value == 61) && (ratio.value >= 39.25)) {
                      res = 'PASS';
                  }
                  
                  if ((concentration.value == 62) && (ratio.value >= 38.50)) {
                      res ='PASS';
                  }
                  
                  // Set this field's value
                  event.value = res;
                  
                  
                  

                   

                  If the code is placed elsewhere, you need to indicate where.

                  • 6. Re: Need Help with Javascript for Acrobat Pro 9
                    mlhend9 Level 1

                    You are awesome!  Thank you so much.

                     

                    I actually was doing the calculations in another field, I moved to the result field....it is working perfectly!