5 Replies Latest reply on Dec 18, 2017 8:17 PM by George_Johnson

    I'm trying to come up with a script that would function as an if/then scenario.

    stepheng54012748

      I'm trying to come up with a script that would function as an if/then scenario.  I very new a writing in JavaScript and have done a reasonable job developing an interactive form.  My form has a section where there are 3 lines of information that adds up to a number.  That number can be either a positive or a negative number which would populate in field "l100".  The other field consists of a number that adds up three fields "l37"+"l38"+"l39" which will always be a positive number this populates in field "l41".  "l41" final number will be determined if field "l100" is a positive or a negative number.  If "l100" is a positive number then "l41" will be the sum of "l37"+"l38"+"l39"+"l100".  If "l100" is a negative number then "l41" will be the sum of "l37"+"l38"+"l39".

       

      Here is the direction I thought might work.  Wondering if I'm on the right track or not:

       

      var theField = this.getField("l100");

      var theValue = theField.value;

      var theField2 = this.getField("l37");

      var theValue2 = theField2.value;

      var theField3 = this.getField("l38");

      var theValue3 = theField3.value;

      var theField4 = this.getField("l39");

      var theValue4 = theField4.value;

       

      if (+theValue > 0) {

          this.getField("l41").value = +theValue + +theValue2 + +theValue3 + +theValue4;

      }

      else {

           this.getField("l41").value = +theValue2 + +theValue3 + +theValue4;  

      }

       

      I've tried to write this up and have had no success.  Any input would be much appreciated.