Copy link to clipboard
Copied
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.
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.
Copy link to clipboard
Copied
Are you using a custom calculation script for the Total field, or one of the other options?
Copy link to clipboard
Copied
Right now I'm using the "Value is the Sum" option, but am open to changing that.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
That works perfectly! Thank you!
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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 = "";
Copy link to clipboard
Copied
That worked, thank you so much! 🙂