Average Radio Button selections but exclude 0's from the equation
this should simple. have seen many posts should have led me answer hours ago still having troubles.
here go:
1) have 9 groups of radio buttons named: gmr1.1_score; gmr1.2_score; gmr1.3_score; gmr1.4_score; gmr1.5_score; gmr1.6_score; gmr1.7_score; gmr1.8_score; gmr1.9_score
2) each group of buttons 4 radio buttons same values in each group:
- "na" have set radio button choice on options tab = 0
- "fair" have set radio button choice on options tab = 1
- "good" have set radio button choice on options tab = 2
- "great" have set radio button choice on options tab = 3
so, form looks bit like:
gmr1.1_score
- na
- fair
- good
- great
gmr1.2_score
- na
- fair
- good
- great
and on. user picks 1 option each question.
my objective average of scores excludes na selections. average, want assign specific text appear.
if did in 2 steps in excel, formulas like:
c7=sum(range)/countif(range,">0")
=if(c7<2,"overall score fair",if(c7<3,"overall score good",if(c7>=3,"overall score great!")))
i thinking following should work count selections not equal "na" excluding getfield("gmr1.”+i+”_score").value==0 counter 1 below isn't!
(the below how trying replicate countif portion of excel formula)
****************************
var counter = 0;
for (i=0; i<=9; i++)
{
if (getfield("gmr1.”+i+”_score").value==1) counter++;
if (getfield("gmr1.”+i+”_score").value==2) counter++;
if (getfield("gmr1.”+i+”_score").value==3) counter++;
}
if (counter>0) {
event.value = counter;
} else event.value = "";
****************************
the sum(range) simple enough using "value sum " on calculate tab of text field properties. if wanted happen in 1 block of code isn't going work me.
****************************
the text assignment based on average value; haven't gotten there yet.
****************************
please help. there has got way of in pretty simple code eluding me.
try following untested code:
// custom calculate script text field
var nonzerofieldcount = 0, sum = 0, v, avg, result;
for (i = 0; < 10; i++) {
// value of current radio button
var v = getfield("gmr1." + + "_score").value;
// increment non-zero field counter if non-zero
if (v !== 0) nonzerofieldcount += 1;
// add value sum
sum += v;
}
// calculate average , determine result
if (nonzerofieldcount !== 0) {
avg = sum / nonzerofieldcount;
if (avg >= 3) result = "overall score great!";
if (avg < 3) result = "overall score good";
if (avg < 2) result = "overall score fair";
} else {
result = "";
}
// set field's value result
event.value = result;
More discussions in PDF Forms
adobe
Comments
Post a Comment