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

Populate text field if a number falls within a specific range

New Here ,
Aug 14, 2017 Aug 14, 2017

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.

Screenshot 2017-08-14 17.01.04.png

TOPICS
PDF forms
2.9K
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
1 ACCEPTED SOLUTION
Community Expert ,
Aug 14, 2017 Aug 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.

View solution in original post

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
Community Expert ,
Aug 14, 2017 Aug 14, 2017

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

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
New Here ,
Aug 14, 2017 Aug 14, 2017

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

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
Community Expert ,
Aug 14, 2017 Aug 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.

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
New Here ,
Aug 14, 2017 Aug 14, 2017

That works perfectly! Thank you!

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
Explorer ,
Jul 26, 2022 Jul 26, 2022

hi I have a similar problem. If I want to set it up as 20 + or - a certain range is there an elegant way to write the if statement?

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

var range = Number(this.getField("Range").value);

if (total>=20 + range && total<=20 + range) event.value = total;

 

something like this?

 

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
New Here ,
Sep 04, 2023 Sep 04, 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?

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
Community Expert ,
Sep 04, 2023 Sep 04, 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 = "";
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
New Here ,
Sep 04, 2023 Sep 04, 2023
LATEST

That worked, thank you so much! 🙂

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