Skip to main content
josephk69933065
Participant
July 19, 2019
Question

How to Generate Numerical Score Based on Text Value

  • July 19, 2019
  • 1 reply
  • 247 views

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

}

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
July 19, 2019

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.