5 Replies Latest reply on Feb 3, 2014 2:12 AM by try67

    Custom Calculation Help Please else if

    Webnmore Level 1

      I have a form which I am using custom calculations please see below, it is working however, the field net$value1 is blank if you manually type in an amount (which we need if the hook field is selected), can someone please steer me in the right direction thanks. So basically I need all calculations to cease if the hook is Yes and allow the user to enter a manual price.

       

       

      image-1.jpg

       

      var a = Number(this.getField("grosswtkg1").value);

      var sum = this.getField("price").value=="KG";

      var hooks = this.getField("hook").value=="Yes";

       

      if (sum)

           {

                           a *= Number(this.getField("price1").value);

                           event.value = a;

                }

      else if (hooks)

            {

                            value0 ="net$value1";

                            event.value = value0;

                          }

       

       

      else

                {

                          var b = Number(this.getField("price1").value);

                          var c = Number(this.getField("qty1").value);

                          var total = b * c;

                          event.value = total;

       

       

                }

       

       

       

       

       

      Thanks

        • 1. Re: Custom Calculation Help Please else if
          try67 MVP & Adobe Community Professional

          You need to re-think the logic behind your code... So if hooks is selected you want to clear the field, otherwise assign a value to it?

          If so, then it needs to be something like this:

           

          if (hooks) {

               event.value = "";

          } else {

               // place the rest of code here

          }

          • 2. Re: Custom Calculation Help Please else if
            Webnmore Level 1

            Thanks Gilad

             

            I am now using the follwoing calculation, the math is working, however, this field net$value1 (gross $ Value excluding GST) is still not showing after you type a figure into it. Any Ideas please.

             

             

            var hooks = this.getField("hook").value=="Yes";

             

            if (hooks) { 

                 event.value = ""; 

            } else if (sum) {

                 var a = Number(this.getField("grosswtkg1").value);

                 var sum = this.getField("price").value=="KG";

                 a *= Number(this.getField("price1").value);

                 event.value = a;

            } else {

                 var b = Number(this.getField("price1").value);

                 var c = Number(this.getField("qty1").value);

                 var total = b * c;

                 event.value = total;

            }

             

                 image-1.png

            • 3. Re: Custom Calculation Help Please else if
              try67 MVP & Adobe Community Professional

              Is this the full code? If so, you have a logical error in it. You're defining the variable "sum" after you've checked its value... That's obviously not going to work.

              • 4. Re: Custom Calculation Help Please else if
                Webnmore Level 1

                Hey Gilad, sorry when redoing it I just messed up and put it in the wrong place, below is the code I am using, as I have stated the custom calculation script is working but the field net$value1 (gross $ Value excluding GST) is blank after typing a value in. Your help is much appreciated!

                 

                 

                var hooks = this.getField("hook").value=="Yes";

                var sum = this.getField("price").value=="KG";

                if (hooks) { 

                     event.value = ""; 

                }  else if (sum) {

                     var a = Number(this.getField("grosswtkg1").value);

                     var sum = this.getField("price").value=="KG";

                     a *= Number(this.getField("price1").value);

                     event.value = a;

                } else {

                     var b = Number(this.getField("price1").value);

                     var c = Number(this.getField("qty1").value);

                     var total = b * c;

                     event.value = total;

                }

                 

                 

                image-2.png

                • 5. Re: Custom Calculation Help Please else if
                  try67 MVP & Adobe Community Professional

                  It's quite difficult to help you out without seeing the actual file... Can you share it? You can email it to me privately at try6767@gmail.com ...