2 Replies Latest reply on Mar 13, 2015 1:28 PM by Sean.twyman

    Custom Calculator or Validtion

    Sean.twyman Level 1

      I have a form with 3 fields. All text boxes.

      "YearlyTotal" - customer input field - formatted as number with $

      "IncentiveLeft" - read only- formatted as number with $

      "IncentiveLevel" - read only  -  no formatting

       

      I tried to enter a number say 500 in the "YearlyTotal" and it should populate the "IncentiveLeft" and "IncentiveLevel" Here is my javascript code and i have tried to put it in both the calculation and validation fields of both "YearlyTotal" & "IncentiveLevel" text box properties and nothing is working. Can someone explain where i went wrong?

       

      var yttl = this.getField("YearlyTotal");
      var ilft = this.getField("IncentiveLeft");
      var ilvl = this.getField("IncentiveLevel");
      if (yttl.value < "500") {
          ilft.value = (500 - number(yttl.value));
          ilvl.value = "1";
      } else if (yttl.value >= "500" && yttl.value < "2000") {
          ilft.value = (2000 - number(yttl.value));
          ilvl.value = "2";
      } else if (yttl.value >= "2000" && yttl.value < "5000") {
          ilft.value = (5000 - number(yttl.value));
          ilvl.value = "3";
      } else if (yttl.value >= "5000" && yttl.value < "10000") {
          ilft.value = (10000 - number(yttl.value));
          ilvl.value = "4";
      } else if (yttl.value >= "10000" && yttl.value < "15000") {
          ilft.value = (15000 - number(yttl.value));
          ilvl.value = "5";
      } else if (yttl.value = "" {
          ilft.value = ""
          ilvl.value = ""
      }
      
        • 1. Re: Custom Calculator or Validtion
          George_Johnson MVP & Adobe Community Professional

          Try the following as the custom Validate script for the YearlyTotal field:

           

          (function () {

           

          // Get the value entered in this field, as a number

          var yttl = +event.value;

           

          // Get references to the other fields

          var ilft = getField("IncentiveLeft");

          var ilvl = getField("IncentiveLevel");

           

          // If the field is blank, set the other fields to blank

          if (!event.value) {

              ilft.value = "";

              ilvl.value = "";

              return;

          }

           

          // Set the other field values

          if (yttl < 500) {

              ilft.value = 500 - yttl;

              ilvl.value = "1";

          } else if (yttl >= 500 && yttl < 2000) {

              ilft.value = 2000 - yttl;

              ilvl.value = "2";

          } else if (yttl >= 2000 && yttl < 5000) {

              ilft.value = 5000 - yttl;

              ilvl.value = "3";

          } else if (yttl >= 5000 && yttl < 10000) {

              ilft.value = 10000 - yttl;

              ilvl.value = "4";

          } else if (yttl >= 10000 && yttl < 15000) {

              ilft.value = 15000 - yttl;

              ilvl.value = "5";

          }

           

          {)();

          • 2. Re: Custom Calculator or Validtion
            Sean.twyman Level 1

            Beautiful. I had to change the last line  from

            {)();

             

             

            to

             

             

            }())

             

             

            thank you so much. i was having a hard time with that one.