Average ignore blanks but does not ignore 0s

New Here ,
Aug 17, 2020 Aug 17, 2020

Copy link to clipboard

Copied

Looking for a Document level script and Field level script that will ignore blanks in the average but will count 0s in the average. I have several fields for subaverages and a cumulaitve average. I have been using these two scripts to ignore blanks but now they want the 0s in the averages. Any suggestions would help!

 

function calcAverage(fields, ignoreBlanks) {
var total = "";
var n = "";
for (var i in fields) {
var f = this.getField(fields[i]);
if (f==null) {
console.println("Error! Can't locate a field called: " + fields[i]);
continue;
}
if (f.valueAsString=="" && ignoreBlanks) continue;
total+=Number(f.valueAsString);
n++;
}
if (n=="") event.value = "";
else event.value = total/n;
}

 

calcAverage(["PLO_1_a", "PLO_1_b", "PLO_1_c", "PLO_1_d", "PLO_1_e"], true, true);

TOPICS
Acrobat SDK and JavaScript, Comment review and collaborate PDF, Create PDFs, Edit and convert PDFs, How to, PDF forms

Views

44

Likes

Translate

Translate

Report

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
Most Valuable Participant ,
Aug 17, 2020 Aug 17, 2020

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

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 17, 2020 Aug 17, 2020

Copy link to clipboard

Copied

Tried that and it's still not working. Any other suggestions?

Likes

Translate

Translate

Report

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 17, 2020 Aug 17, 2020

Copy link to clipboard

Copied

LATEST

Likes

Translate

Translate

Report

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