1 Reply Latest reply on Oct 16, 2009 12:49 PM by try67

    Warning Message only if 1 to 3 fields do not equal 100%

    rwesterpchef Level 1

      I have 3 potential fields that will be completed.  If Field1 (Primary Beneficiary) is 100%, then the user will leave Fields 2 and 3 empty.  If Fields 1 and 2 equal 100%, then Field 3 will be empty.  Otherwise they will have values in Fields 1, 2, and 3.  Regardless, they should not be able to continue completing the rest of the form until the sum of these three fields equal 100%.  Therefore I did modify the form as follows, but two issues: it throws the error message up even when first entering a value in Field 1.  This script need NOT run until all 3 fields have been tabbed through, or they click on the next section of the form to continue completing.  The "Total 100" (name of this particular field) is in the Tab Order to appear after "Beneficiary 3 Benefit Percent" field.  And secondly, it still permits the user to continue rather than returning to Field1 even if the total does not equal 100%.  Your assistance is greatly appreciated!  PS:  How do I mark that the post was either helpful or correct?

      Rita

       

      event.value = ''; // clear field

       

      // get the values of Beneficiary Benefit fields 1, 2 and 3 as string
      var sField1 = this.getField("Beneficiary 1 Benefit Percent").value.toString();
      var sField2 = this.getField("Beneficiary 2 Benefit Percent").value.toString();
      var sField3 = this.getField("Beneficiary 3 Benefit Percent").value.toString();

       

      // adjust for a field being 100 and others null
      if (sField1 == 100 & sField2 == '' & sField3 == '') sField2 = "0" , sField3 = "0";
      if (sField2 == 100 & sField1 == '' & sField3 == '') sField3 = "0" , sField1 = "0";

       

      // do only if Beneficiary Benefit fields 1, 2 and 3 are not null
      if(sField1 != '' & sField2 != '' & sField3 != '') {
      event.value = Number(sField1) + Number(sField2)+ Number(sField3);
      if (event.value != 100) app.alert("The sum of Benefit percent must equal 100.", 1, 0);
      }

      this.getField("field 1").setFocus();

        • 1. Re: Warning Message only if 1 to 3 fields do not equal 100%
          try67 MVP & Adobe Community Professional

          Two problems just from a first glance at this line:

          if (sField1 == 100 & sField2 == '' & sField3 == '') sField2 = "0" , sField3 = "0";

          1. You're comparing a string to a number

          2. You're separating commands with a comma and not placing {} around the block of commands.

          It needs to be something like this:

          if (sField1 == "100" & sField2 == "" & sField3 == "") {sField2 = "0"; sField3 = "0";}

           

          There are probably more errors, but start by fixing those.

          Also, you should probably post which error message you're getting.