1 Reply Latest reply on Nov 14, 2012 10:31 AM by try67

    How do I write a validation script on a calculated field button?



      I created a fillable pdf form and wanting to validate a calculated field.  The user can enter a percentage in 4 different fields, but they should either equal or total 100%.  I made a hidden button underneath to calculate those 4 cells.  I'd like to have an alert message pop up if those 4 cells don't equal 100 to say "Percentage must total 100%.  Please re-enter." I thought having the calculated field would make it easier since I'd only need to write script in one field.


      Looks like this:

      Header 1Header 2
      field 110   %
      field 220    %
      field 320    %
      field 40     %
      hidden field calculates sum50


      Can anyone help me with the script code?


      Much appreciated,


        • 1. Re: How do I write a validation script on a calculated field button?
          try67 MVP & Adobe Community Professional

          You can use a calculation field to sum up the fields, and then check if the value is 100 or not, and alert the user.

          One extra thing you should do is check if all the fields are actually filled-in. If not, it would be quite annoying to get this error message each time you change the value of one of the fields.


          You can use something like this:

          var v1 = this.getField("field1").valueAsString;

          var v2 = this.getField("field2").valueAsString;

          var v3 = this.getField("field3").valueAsString;

          var v4 = this.getField("field4").valueAsString;

          event.value = (+v1) + (+v2) + (+v3) + (+v4);


          if (event.value!=100 && v1!="" && v2!="" && v3!="" && v4!="") {

          app.alert("Percentage must total 100%.  Please re-enter.");