1 Reply Latest reply on Jan 31, 2015 5:50 PM by gkaiseril

    How to create a calculation script for VO2max using text field values on a pdf form.

    jat0216

      I am attempting to create a script that calculates VO2max based upon user input into several text fields.

       

      My form is set up so that the user can input values into 4 text fields:

       

      1. Weight = body weight in kilograms

      2. Age = age in years

      3. Time = time to walk 1 mile as a decimal number

      4. Heart rate (HR) = recovery heart rate immediately upon finishing the 1-mile walk

       

      The equation for VO2max that I am using is:

       

      VO2max = 132.853 - (0.1692*Weight) - (0.3877*Age) + (6.315) - (3.2649*Time) - (0.1565*HR)

       

      After the user enters values into the 4 text fields, I want the VO2max text field to automatically calculate the above equation and display the result for the user to see so that the user doesn't have to input all of those numbers into a calculator.

       

      Any suggestions on how to write the script?

        • 1. Re: How to create a calculation script for VO2max using text field values on a pdf form.
          gkaiseril MVP & Adobe Community Professional

          Assuming your field names are what you entered into the formula you can use the simplified field notation of::

           

          132.853 - (0.1692 * Weight) - (0.3877 * Age) + (6.315) - (3.2649 * Time) - (0.1565 * HR)

           

          If you want the value to only show after al the data fields are complete than you need to use a JavaScript calculation:

           

           

          function GetField(cName) {
          var oField = this.getField(cName);
          if(oField == null) app.alert("Error accessing field " + cName + "\nPlease check the field name.", 1, 0);
          return oField;
          }

          var Weight = GetField("Weight");
          var Age = GetField("Age");
          var Time = GetField("Time");
          var HR = GetField("HR");

          event.value = "";
          if(Weight.value !=0 && Age.value != 0 && Time.value != 0 && HR.value != 0) {
          event.value =  132.853 - (0.1692 * Weight.value) - (0.3877 * Age.value) + (6.315) - (3.2649 * Time.value) - (0.1565 * HR.value);
          }