Skip to main content
Participant
August 14, 2017
Answered

Populate text field if a number falls within a specific range

  • August 14, 2017
  • 2 replies
  • 2902 views

Hello! I'm hoping someone here can help me with this. I'm working on a form in Adobe Acrobat XI. The form is basically a survey that uses radio buttons. Each choice has an associated numerical value, and these values must be totaled to give the user a score. I've figured out how to get a total score based on the values of the radio buttons selected, and am using a calculation in a hidden field to do that. Now I'd like to use text fields to display the score next to the appropriate range, but I don't know how to do so. There are four ranges, and I'd like for it only to display next to the appropriate one. How would I do that, assuming the name of the hidden field is "Total"? So in the picture below, if the user had a score of 30, it would show up in a text field to the left of the "26-38" range, but not in the other three boxes.

This topic has been closed for replies.
Correct answer try67

No, that's fine. Leave it as is.

As the custom calculation script of "16-24", for example, use this script:

var total = Number(this.getField("Total").value);

if (total>=16 && total<=24) event.value = total;

else event.value = "";

You can use the same code for the other fields, just adjust the values in the second line.

2 replies

Participant
September 4, 2023

Hi, I have a similar issue:  I have one text field whic I would like to populate based on a variety of outcomes based on the calcuation in another field: i.e.

If total number is between 4 and 5 = 'No Risk'

If total number is between 6 and 9 = 'Cautious'

If total number is between 10 and 13 = 'Balanced'

etc... I have tried adding one line to the exisitng script withour success.  Can you help please?

try67
Community Expert
Community Expert
September 4, 2023

Try this:

 

var total = Number(this.getField("Total").valueAsString);
if (total>=4 && total<=5) event.value = "No Risk";
else if (total>=6 && total<=9) event.value = "Cautious";
else if (total>=10 && total<=13) event.value = "Balanced";
// etc.
else event.value = "";
Participant
September 4, 2023

That worked, thank you so much! 🙂

try67
Community Expert
Community Expert
August 14, 2017

Are you using a custom calculation script for the Total field, or one of the other options?

jds0901Author
Participant
August 14, 2017

Right now I'm using the "Value is the Sum" option, but am open to changing that.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 14, 2017

No, that's fine. Leave it as is.

As the custom calculation script of "16-24", for example, use this script:

var total = Number(this.getField("Total").value);

if (total>=16 && total<=24) event.value = total;

else event.value = "";

You can use the same code for the other fields, just adjust the values in the second line.