Results 1 to 3 of 3

Thread: Calculating averages when not all items have values

  1. #1
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Calculating averages when not all items have values

    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.

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!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>
    Last edited by vwphillips; 01-27-2010 at 12:40 PM.
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. #3
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you so much!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •