2 Replies Latest reply on Nov 20, 2012 12:06 PM by ahlaj77

    Help with conditional statement if/else (image included)

    ahlaj77

      Statement.jpg

      Hello to all!

      Trying to get my if/else statement to work but its not working :/. I need a second opinion and how I can make it work. This code will be going in the Total Price column (where it says $0.00). Thank you in advance!

       

      Here is what I am trying to accomplish:

       

      1. If the units are below 150 then no discount is applied.
      2. If the units are 150-299 then apply a 40% discount.
      3. If the units are 300+ then apply a 50% discount.

       

      var v1 = this.getField("txtDoughUnit1").value;
      var total = v1 * 14;

       

      if(150 > total) event.value = total;

       

      else if((total >= 150 ) && (total < 300)) event.value = total * 0.40;

       

      else if(300 >= total) event.value = total * 0.50;

       

      else event.value = 0;

        • 1. Re: Help with conditional statement if/else (image included)
          gkaiseril MVP & Adobe Community Professional

          What is not working in your script?

           

          Check your comparison operator for the units below 150.

           

          Adding comments to your code can make your code easier for others to read and help you at a later date when you need to update the code.

           

          I would use the "switch" statement.

           

          // units for computing discount

          var nTotal = this.getField("txtDoughUnit1").value * 14;

          // select when statement is true

          switch(true) {

          case (nTotal >= 300) :

          // total greater than 300

          event.value = nTotal * 0.50;

          break; // end greater than 300

           

          case (nTotal >= 150 ) :

          // total greater than or equal to 150 and less than 300

          event.value = nTotal * 0.40;

          break; // end greater than or equal to 150, greater than 300 all ready done

           

          default:

          // all other values

          event.value = 0;

          break;

          } // end of switch decision

          1 person found this helpful
          • 2. Re: Help with conditional statement if/else (image included)
            ahlaj77 Level 1

            Thanks! I was able to take your code and tweak it and I have it working now. Your help is much appreciated! I have never used the Switch statement before. Learn something new every day!