I have a form that I am doing for a client where I need to calculate a total as follows:
I have a column with 9 aspects that need to be rated via radio buttons. Then I have a row with 5 radio buttons: Each of the radio buttons can get a value of (5) (4) (3) (2) (1) by selecting the appropriate radio button for each of the aspects. So I end up with 9 rows of 5 radio buttons.
The calculation I need code for is for calculating the grand total of all those radio buttons that are selected and divide the total by 45. All of this needs to be done in only "one" field at the end called "total" by hitting a button labeled "calculate"
I am using acrobat pro 8
PLEASE HELP ME!!
So if I have 9 rows of radio buttons with a name template of "Aspect.#" where '#' is the row number starting at zero and going to 8. Each row of buttons has 5 buttons that have a button with a value from 1 through 5. For your total field, you can use one of the following scripts for the custom calculation script:
// using hierarchical field names
// variable for value of row
var nValue = 0;
// variable for the sum of the rows
var nSum = 0
// locate the top level radio button name
var oAspect = this.getField('Aspect');
// convert top level field object to an array of fields
var aAspect = oAspect.getArray();
// loop through each index (row) of aspect array
for (i = 0; i < aAspect.length; i++) {
// get the value of row i
nValue = aAspect[i].value;
// adjust for no selection
if (nValue == "Off") nValue = 0;
// add the value for the row i
nSum += nValue;
} // end loop trough fields
// compute the value and populate result field
event.value = nSum / 45;
// using field names in an array
// variable for value of row
var nValue = 0;
// variable for the sum of the rows
var nSum = 0
// make array of field names
var aAspect = new Array("Aspect.0", "Aspect.1", "Aspect.2",
"Aspect.3", "Aspect.4", "Aspect.5", "Aspect.6", "Aspect.7",
"Aspect.8");
// loop through fields (row) of aspect array
for (i = 0; i < aAspect.length; i++) {
// get the value of row i
nValue = this.getField(aAspect[i]).value;
// adjust for no selection
if (nValue == "Off") nValue = 0;
// add the value for the row i
nSum += nValue;
} // end loop trough fields
// compute the value and populate result field
event.value = nSum / 45;
George Kaiser