7 Replies Latest reply on May 11, 2011 7:40 PM by 9911dave

    IF statements

    9911dave

      I need to create an "IF" calculation in a field and have no idea how to state it in JavaScript.  Basically what I need is:

       

      IF Size1 * Unit1 > 5 then Size1 * Unit1 else $5.00

       

      In advance thanks for your assistance.

        • 1. Re: IF statements
          MarkWalsh Level 4

          Using an 'If' statement:

           

          var size1 = this.getField("Size1").value

          var unit1 = this.getField("Unit1").value

          var total = size1 * unit1

          if (total > 5) {

          event.value = 5

          } else {

          event.value = total

          }

           

           

          Using a 'Min' calculation

           

          var size1 = this.getField("Size1").value

          var unit1 = this.getField("Unit1").value

          var total = size1 * unit1

          event.value = Math.min(5, total)

          • 2. Re: IF statements
            9911dave Level 1

            Thanks for the response....... Although, I can't seem to

            get either of the solutions to work.  I am entering the formula in the "Custom calculation script" area in Text Field Properties.  Am I doing something wrong.

            • 3. Re: IF statements
              MarkWalsh Level 4

              Are the names of your 2 fields correct? (I assumed they were "Size1" and "Unit1")

              • 4. Re: IF statements
                9911dave Level 1

                Yes, the field names are correct.  The result of the function is in a field

                named "Price1".


                • 5. Re: IF statements
                  MarkWalsh Level 4

                  Then it should be working if you put it into the 'Custom Calculation Script' (It's working here in my test file). Note that the field names MUST be typed EXACTLY the same in the script where the 'getField' lines are used - including punctuation (i.e. 'Price1' or 'PRICE1' won't work if the field is named 'price1')

                  • 6. Re: IF statements
                    9911dave Level 1

                    TO WORKS!!!  It seems that a couple of the field names were lower case and the others upper case.  Also the > (greater than) should have been a < (less than).  That aside, thank you so much for your help.

                    • 7. Re: IF statements
                      9911dave Level 1

                      OH - OH I should tell you the whole deal.  I am making a "work order form" with ten entry lines.  I got all the formulas change so they now work, but on lines where I have a blank (null) entry, the result comes up as $5.00.  Do we need a "null" statement in the function for cases where less than 10 entries are made?