1 Reply Latest reply on Oct 24, 2015 12:03 PM by MatLac

    If, else JavaScript question


      I need some help please. I have a form with five boxes in a column, we’ll call them box1, box2, box3, box4, and box 5.


      Boxes 1, and 2 when added together equals box 3, and when boxes 4 and 5 are added together it also equals box 3.


      For example 1+4=5=2+3.

      Boxes 1,2,4,and 5 are manually inserted.


      What I would like to do is to make sure box 3 is true for both calculations and if false it shows “Error”. And
      if boxes 4 and 5 aren’t entered by the user, it just shows the calculation of box1+box2.


      Please help! THANKS!!

        • 1. Re: If, else JavaScript question
          MatLac Level 3

          Assuming your boxes only contains numbers


          var vBox1 = this.getField("box1").value;

          var vBox2 = this.getField("box2").value;

          var vBox3 = this.getField("box3").value;

          var vBox4 = this.getField("box4").value;

          var vBox5 = this.getField("box5").value;

          var result1 = vBox1+vBox2;

          var result2 = vBox4+vBox5;

          if ((result1 == result2)&&(result1 == vBox3)){

               //insert your code here



               //insert your code here


          this handles the first part of what you want.  What if the user enters only box 1, 2 and 4? do you want the error to show or just the sum of 1+2, or both?  Basiccaly, box 3 should always be the sum of 1 + 2 and be read only right?