How to Generate Numerical Score Based on Text Value

New Here ,
Jul 19, 2019

Copy link to clipboard

Copied

I am trying to write script to apply a generate score based on selected text values in a drop down list. So for a field named "Likelihood" the values would be as follows -- Low; Low to Moderate; Moderate; Moderate to High; High.  I want to produce a score based on each rating --

Low=1

Low to Mod=2

Mod=3

Mod to High=4

High=5

I have been able to write the script for the inverse where a numerical selection produces the text rating.  But I need the opposite of that.

var v = this.getField("Dropdown1").value;

if (v=="") event.value = "";

else {

     v = Number(v);

     if (v<2) event.value = "Low";

     else if (v<3) event.value = "Low to Moderate";

     else if (v<4) event.value = "Moderate";

     else if (v<5) event.value = "Moderate to High";

     else if (v<6) event.value = "High";

}

TOPICS
Acrobat SDK and JavaScript

Views

51

Likes

Translate

Translate

Report

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

How to Generate Numerical Score Based on Text Value

New Here ,
Jul 19, 2019

Copy link to clipboard

Copied

I am trying to write script to apply a generate score based on selected text values in a drop down list. So for a field named "Likelihood" the values would be as follows -- Low; Low to Moderate; Moderate; Moderate to High; High.  I want to produce a score based on each rating --

Low=1

Low to Mod=2

Mod=3

Mod to High=4

High=5

I have been able to write the script for the inverse where a numerical selection produces the text rating.  But I need the opposite of that.

var v = this.getField("Dropdown1").value;

if (v=="") event.value = "";

else {

     v = Number(v);

     if (v<2) event.value = "Low";

     else if (v<3) event.value = "Low to Moderate";

     else if (v<4) event.value = "Moderate";

     else if (v<5) event.value = "Moderate to High";

     else if (v<6) event.value = "High";

}

TOPICS
Acrobat SDK and JavaScript

Views

52

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 19, 2019 0
try67 LATEST
Most Valuable Participant ,
Jul 19, 2019

Copy link to clipboard

Copied

Drop this line:

v = Number(v);

And reverse the if-conditions:

if (v=="Low") event.value = "2";

else if (v=="Low to Moderate") event.value = "3";

etc.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 19, 2019 0