Hi everyone,
I've created a questionnaire in Acrobat using the some radio buttons. There are about 14 questions and the user has to answer the question by clicking a radio button next to the letter (A) or alternatively next to the letter (B). An example of this is as follows:
1) With regard to snacking, do you:
[radio button is here] (A) Tend to do better with snacks between meals
[radio button is here] (B) Tend to last between meals easily in general
At the end of the questionnaire are two fields. Next to the first field is a label saying "Total A Answers", then next to the second field is a label saying "Total B answers".
I've created a button which when clicked, I'd like the total amount of A answers inserted into the first field and the total amount of B answers inserted into the second field.
Does anyone know what javascript I'd use to create these calculations? Also, would I have to give the value for each of the radio buttons a value of 1 or A and B?
Would really appreciate any help.
Name the radio buttons for each question with a number e.g. Row 1 (Qu.1), Answer A & B = '1', Row 2 (Qu.2), Answer A & B = '2' and so on. Each pair must have the same name in order to be mutually exclusive (which you have probably setup already). The export value for Answer A = 1 and for Answer B = 2.
Underneath each column setup a text field to handle the calculation, with a name such as 'subTot1' and 'subTot2'. In the Custom Calculation tab for each subtotal field add the following script:
//code start
var cols = 2; //number of columns (answers)
var sum; //temporary variable to sum columns
for(i = 0 ; i < cols; i++) {
sum = 0; // clear sum variable
// loop through check boxes in column i
for(j = 0; j < 20; j++) {
// if value of check box equal the export
// value for the column then increment the sum
if(this.getField(j + 1).value == (i + 1)) sum++;
} // end loop through column i fields
// set field value equal to sum
this.getField("subTot" + (1 + i)).value = sum;
} // end loop through columns
//code end
This is easily extendable to more columns (for things like surveys etc.).
For each additional column, the export value needs to increase (e.g. column 3 export value = 3, column 4 = 4 and so on) and change the value of the 'cols' variable accordingly.
I hope this is useful to you.