Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Rating based on score script issue

Guest
Jul 22, 2016 Jul 22, 2016

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";

TOPICS
Acrobat SDK and JavaScript
321
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jul 22, 2016 Jul 22, 2016

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) :
cEvaluatio

...
Translate
LEGEND ,
Jul 22, 2016 Jul 22, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 22, 2016 Jul 22, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 22, 2016 Jul 22, 2016
LATEST

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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines