Copy link to clipboard
Copied
Greetings! I’m creating a rating form in Adobe Acrobat that has several fields in each section. Each field has a dropdown menu with the following options: (Choose one, N/A, 1, 2, 3, 4, 5). If I choose N/A or leave it as “Choose one,” Adobe sees it as zero and includes it in the average rating, lowering the overall score. What formula do I create so that only the numbers get averaged out?
Please note: I looked at other similar questions, but suggested formulas did not work for me. Help!
Copy link to clipboard
Copied
That means some of the values of the fields could not be converted to a number.
Are you sure the value is actually "N/A" and not something else? To avoid such issues change these two lines:
var v = this.getField("Q"+i).valueAsString;
if (v!="Off" && v!="N/A") {
To:
var v = Number(this.getField("Q"+i).valueAsString);
if (!isNaN(v)) {
Copy link to clipboard
Copied
Let's say the question fields are called Q1 to Q10. You can then use this code as the custom calculation script of your average field:
var total = 0;
var n = 0;
for (var i=1; i<=10; i++) {
var v = this.getField("Q"+i).valueAsString;
if (v!="Off" && v!="N/A") {
n++;
total+=Number(v);
}
}
if (n==0) event.value = "";
else event.value = total/n;
Copy link to clipboard
Copied
This worked! But NaN is now showing up in the area where I would like it blank (where the average is supposed to appear). How do I fix this?
Copy link to clipboard
Copied
That means some of the values of the fields could not be converted to a number.
Are you sure the value is actually "N/A" and not something else? To avoid such issues change these two lines:
var v = this.getField("Q"+i).valueAsString;
if (v!="Off" && v!="N/A") {
To:
var v = Number(this.getField("Q"+i).valueAsString);
if (!isNaN(v)) {