3 Replies Latest reply on Nov 12, 2013 1:48 PM by gkaiseril

# PDF Form: Multiple Choice sheet that displays a percentage based on answers provided

Hello,

Im trying to create a form that has 4 multiple choice questions, the answers to each being the values 0,1,2,3,4, 5 or N/A.

Once answers are given, I'd like the percentage to appear on the form.

I can't figure out how to do this, as the total fluctuates depending on if the response to one or more questions is "N/A".

I.e. if the answers were as follows: 4,4,4,4, the percentage would be 80% (16/20).

However, if the answers were: 4,4,4,N/A, the percentage would also be 80% (12/15) and NOT 60% (12/20).

I figure its a javascript thing - but alas I do not know Java.

Help Please!

• ###### 1. Re: PDF Form: Multiple Choice sheet that displays a percentage based on answers provided

Also - Im using radio boxees for the multiple choice answers.

• ###### 2. Re: PDF Form: Multiple Choice sheet that displays a percentage based on answers provided

This is how I've been able to do it so far....  Let me know if you can think of a simpler way!

First, I set up the values of the multiple choice answers to be 1,2,3,4,5,6, and an "N/A" response value is 0.

Then I created a subtotal box with the following custom script to generate a total based on the number of questions that aren't answered with a "N/A".

(The variable x,y,z,w are for each question.)

var x=5;

var y=5;

var z=5;

var w=5;

if (this.getField("b1").value=="0" )

x = 0;

if (this.getField("b2").value==0 )

y = 0;

if (this.getField("b3").value==0 )

z = 0;

if (this.getField("b4").value==0 )

w = 0;

event.value = x + y + z + w;

• ###### 3. Re: PDF Form: Multiple Choice sheet that displays a percentage based on answers provided

So you want to compute the percentage of the non-"N/A" selections using the count of selected items * 5 as the denominator and then use that value to divide the sum of the values for the non-"N/A" selections.

Has a default checked value been selected.

Since the averaging is not just computation of the mean based on the item count, you to create a custom JavaScript calculation.

var aNames = new Array("Radio Button.0", "Radio Button.1", "Radio Button.2", "Radio Button.3"); // array of field names

var aValues = new Array();

var sum = 0;

var count = 0;

var oField;

event.value = "";

for(i = 0; i < aNames.length; i++) {

// get values of fields into array;

oField = this.getField(aNames[i]);

if(oField ==  null) app.alert("Error getting " + aNames[i] + " field!", 0, 1);

else aValues[aValues.length] = oField.value;

}

if(aValues.length != 0) {

// sum the non-N/A vlaues in the array;

for(i = 0; i < aValues.length; i++) {

if(String(aValues[i]).toUpperCase() != "N/A") {

sum += Number(aValues[i]); // sum the non-N/A values;

count++; // count the non-N/a values;

}

}

}

// compute average if count not zero;

if(count != 0) event.value = sum / (count * 5);