These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Using Calculating Function

HR Lady4
Registered: Nov 2 2010
Posts: 25

Please help.
 
I have (5) combo boxes named "Rating 1, Rating 2", etc...I then have a Text Field entitled "Score". I'm trying to calculate the average score of the 5 combo boxes. However if a combo box is left blank, the text field "score" is still averaging the "zero". How can you get it not to average unless a figure is displayed?
 
Also- is there a way to create a "blank" option under "options" under the combo box property mode?
 

My Product Information:
Acrobat Pro 9.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You cannot create a blank item in a combo box. People commonly use a single space instead, which looks blank.

To calculate the correct average, you'll have to use JavaScript. You can then check the field value, and if it is equal to the "blank" value, exclude it from the calculation. For example:


// Custom calculate script for text field
(function () {

var v;
var count = 0;
var sum = 0;

// Loop through combo boxes
for (var i = 1; i < 6; i++) {
v = getField("Rating " + i).value;
if (v !== " ") {
count++; // Increment counter
sum += v; // Add value to sum
}
}

// Calculate average
if (count) {
event.value = sum / count;
} else {
event.value = "";
}

})();
HR Lady4
Registered: Nov 2 2010
Posts: 25
Yeahhh it worked!!! You made my day!!