PDA

View Full Version : Calculating averages when not all items have values



PhoebeDog
01-27-2010, 04:25 AM
Greetings All,

I know some of you experts will be able to help me.

I have a form in Adobe that lists ratings for various tasks, ranking from 1-3. I need to put in a box that tabulates the average for the section. That is itself has thus far been pretty simple.

My problem is that the number of tasks is variable. There may be 8 tasks on one form, but only 2 on another. Is there a way to calculate the average of only the number of ratings that are actually 1-3, leaving out the ones that have no ratings because there is no task? In other words, I can't just say to calculate the average of the 8 items, because there may be only two tasks that have been rated.

I hope this makes sense and that someone can help! Thanks in advance for any assistance you can provide.

vwphillips
01-27-2010, 12:34 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/

function Test(){
var frm=document.forms[0];
for (var av=0,z0=1;frm['q'+z0];z0++){
frm['q'+z0].value=frm['q'+z0].value.replace(/\D/g,'');
if (frm['q'+z0].value){
av+=frm['q'+z0].value*1;
}
}
frm['average'].value=av/(z0-1);
}
/*]]>*/
</script></head>

<body>
<form>
<input name="q1" />
<input name="q2" />
<input name="q3" />
<input name="q4" />
<input name="average" />
<input type="button" name="" value="test" onclick="Test();"/>
</form>
</body>

</html>

PhoebeDog
01-28-2010, 01:11 PM
Thank you so much!