3 Replies Latest reply on Jul 22, 2016 9:48 AM by gkaiseril

    Rating based on score script issue

    michaeld11872189

      I'm trying to get a form to auto populate a rating in a text box based on the percentage displayed in another text box.  It just isn't working and I've tried many ways of writing it.

       

      var score = this.getField("948 Score").value;

       

      if (score == 100) event.value = "Commendable";

       

      else if (score <= 99 && score >= 80) event.value = "Trained";

       

      else if (score <= 79 && score >= 65) event.value = "Practiced";

       

      else if (score <= 64) event.value = "Untrained";

        • 1. Re: Rating based on score script issue
          gkaiseril MVP & Adobe Community Professional

          Have you looked at the computed percentage value stored in the field?

           

          Unless you multiply by 100 the computed value for a percentage field is the decimal value from the division computation. The values usually fall between 0 and 1.00  When you set the format of the field to "Percentage" the value of the field is multiplied by 100 and gets the percentage symbol appended to the displayed value.

           

          Note that the displayed value for a field is not always the value of the field.

           

           

          Instead of using a nested if statement, one could use the switch statement.

           

          var cEvaluation;

          var nScore = this.getField("948 Score").value;

          switch(true)

          {

          case (nScore == 1) :

          cEvaluation = "Commendable";

          break;

          case (NScore >= 0.8) :

          cEvaluation = "Trained";ASxxxx

          case NScore >= 0.65 :

          cEvaluation = "Practiced";

          break;

          default:

          cEvaluation = "";

          break;

          } // end switch;

          event.vaue = cEvaluation;

           

          When the statement after "case" is meet the following block of code is run to the break and then control leaves the rest of the switch tests.

          • 2. Re: Rating based on score script issue
            michaeld11872189 Level 1

            Not working.  When changing the score to any percentage it's stuck on "Commendable"

            • 3. Re: Rating based on score script issue
              gkaiseril MVP & Adobe Community Professional

              Sorry a typo in the script.

               

              Either of the following will work:

               

              var score = this.getField("948 Score").value;
              var Rating;
              if (score == 1) Rating = "Commendable";
              else if (score <= .99 && score >= .80) Rating = "Trained";
              else if (score <= .79 && score >= .65) Rating = "Practiced";
              else if (score <= .64) Rating = "Untrained";
              event.value = Rating;


              var cEvaluation;
              var nScore = this.getField("948 Score").value;
              switch(true)
              {
              case (nScore == 1) :
              cEvaluation = "Commendable";
              break;
              case (nScore >= 0.8) :
              cEvaluation = "Trained";
              case nScore >= 0.65 :
              cEvaluation = "Practiced";
              break;
              default:
              cEvaluation = "Untrained";
              break;
              } // end switch;
              // event.vaue = cEvaluation;