9 Replies Latest reply on Feb 8, 2012 7:56 AM by MeridianFlyer

    how to use if then statements to restrict values

    MeridianFlyer

      I'm using a custom calculation script in a PDF form field that pulls subtotals from several other fields. My question is how can I use if then statements to prevent users from entering numeric values that exceed 100 in the fields that are used to calculate the subtotal fields? The document has eight fields in which the user selects a value that is multiplied by a set value based on a radio button selection which then results in the subtotal for that item. The values selected in these eight fields cannot exceed 100, with the additional restriction that  if optional item seven and optional item eight are selected they cannot exceed 15, which means item one through items six must total no more than 85. Where would such an if/then statement be placed -- as a validation script in each of the eight fields on which the calculation is based?

       

      My total calculation field is:

       

      (function() {

         // Get the field values, as numbers

      var v1 = +getField("Duty1Score").value;
      var v2 = +getField("Duty2Score").value;
      var v3 = +getField("Duty3Score").value;
      var v4 = +getField("Duty4Score").value;
      var v5 = +getField("Duty5Score").value;
      var v6 = +getField("Duty6Score").value;
      var v7 = +getField("Objective1Score").value;
      var v8 = +getField("Objective2Score").value;

      // Perform the calculation

         var result = (v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8) / 100;


      // Set the value of this field to the result

         event.value = result;

      })();

       

      Thanks for any help you can provide.