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

Finding Average but withholding certain fields

ben.smith
Registered: Dec 16 2008
Posts: 11

I have 8 sections for a survey and each receive a percentage score that is averaged at the end of the survey to give an overall score.

I am running into an issue because 2 of the sections might not get filled out depending on the companies circumstances and thus throwing off my averages at the end. Is there a way to get a better average if the participant hasn't filled out a particular area?

I am using Acrobat Pro 8.1.3 and can calculate the averages but if they don't fill out a section it gives them a 0% thus throwing everything off.

I can give more details if needed but really need to figure this out. Any help would be great. Thanks.

My Product Information:
Acrobat Pro 8.1.3, Macintosh
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
How are you currently calculating the averages? Are you using the built-in method or are you using a custom calculation JavaScript? If JavaScript, can you post what you're currently using?

George
ben.smith
Registered: Dec 16 2008
Posts: 11
I am using the built in standard notations right now, but figure it needs to be written with some javascript and that is where I am stuck.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Yes, you will need to use JavaScript, but without more information it's hard to suggest specific code. But the basic approach would be to get the relevant field values to determine if the section is filled-in. If so, then include the data in the calculation. For example:

// Get three field values, as strings so we can differentiate between// a blank field and a value of zerovar v1 = getField("Text1").valueAsString;var v2 = getField("Text2").valueAsString;var v3 = getField("Text3").valueAsString; // Initialize variables;var sum = 0;var count = 0; // Deal with the first variableif (v1 !== "") {sum += +v1;count += 1;} // Deal with the second variableif (v2 !== "") {sum += +v2;count += 1;} // Deal with the third variableif (v3 !== "") {sum += +v3;count += 1;} // Calculate the average of the non-blank fields// and set this field value to the resultif (count) {event.value = sum / count;} else {event.value = "";}

This is not necessarily the best and most efficient way to code this, but should demonstrate the basic idea. It assumes the input fields are numeric.

George
ben.smith
Registered: Dec 16 2008
Posts: 11
This is definitely over my head I believe. I understand the basic premise you are stating in your post above but was hoping I could give you more specifics in order to provide me with a more full answer since I am a beginner at Javascript:

There are 8 text fields and each hold a percentage total. I want to get the average of these 8 fields to display in a final text field titled "overall score."

All of the 8 text fields will have a percentage, but Sections 4 and 5 may not get a total, resulting in a 0% in that field. This will ultimately ruin the average overall unless I can somehow have the document withhold one or both of these sections if their value is 0%. So if section 4 was returning a value of 0%, then the average would be based on only 7 sections instead of eight. And if both sections 4 and 5 were returning a 0%, then the average would be based on 6 sections instead of eight.

Hopefully this makes sense and you can help me further. Thank you again for all your help.