Skip to main content
Participant
November 15, 2024
Answered

How to select dropdown option based on data in TextField

  • November 15, 2024
  • 1 reply
  • 696 views

Hello,

 

I'm trying to navigate my way through sciripting for the first time., all to make an evaluation form that autocalculates for the evaluators. 

 

I've figured out (thanks to this community) how have a textfield change its value based on a drop down, how to set a text field to average the numbers in other fields. 

 

Now I'm at the final step: Based on the average number in the TextField ("Average"), I need the dropdown box ("Overall") to change.

- If "average" is <1.75, "Overall" should select "DNME"

- if "Average" is >-1.75 but <2.75, "Overall" should select "ME"

-if "average" >2.75, "Overall" should select "EE".

 

I've scoured the other posts, but I haven't found an answer yet that works. Does anyone have an answer or a link to where I could find it?

This topic has been closed for replies.
Correct answer try67

Change the "Overall" field to a text field and use this code as its custom Calculation script:

 

var average = Number(this.getField("Average").valueAsString);
if (average<=1.75) event.value = "DNME";
else if (average<=2.75) event.value = "ME";
else event.value = "EE";

 

Note: I added to your conditions the cases in which the values are exactly 1.75 or 2.75, since you didn't specify them.

Also, if the Average field is empty it will treat it like zero and show "DNME". If you don't want that to happen then let us know what should be the value in that case.

1 reply

try67
Community Expert
Community Expert
November 15, 2024

Why a drop-down? Do you want the user to be able to override this value and change it to something else?

Participant
November 15, 2024

That is the best question. I didn't even think about changing it to another field. I don't want the user to override it. So I gues this is a new question:

 

How to have the value in one field set the value in another field?

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
November 15, 2024

Change the "Overall" field to a text field and use this code as its custom Calculation script:

 

var average = Number(this.getField("Average").valueAsString);
if (average<=1.75) event.value = "DNME";
else if (average<=2.75) event.value = "ME";
else event.value = "EE";

 

Note: I added to your conditions the cases in which the values are exactly 1.75 or 2.75, since you didn't specify them.

Also, if the Average field is empty it will treat it like zero and show "DNME". If you don't want that to happen then let us know what should be the value in that case.