help for javascript code inside db activity

help for javascript code inside db activity

by Nicola Ribatti -
Number of replies: 1

Hi anyone

I've created a db activity in which users have to insert their name, activity type and hours of activity. I woul like to have (via javascript) the summary of the hours for each user in the view list tab.

I've found in the forum a script like this:

______________

var timespent = 0;
var totalHrs = 0;

function timecount () {
   var timespent = document.getElementsByClassName("singleservice");
         for (i=0; i < timespent.length; i++) {
         totalHrs += timespent[i].innerHTML*1;
      }
document.getElementsByClassName("totalHrs")[0].innerHTML = totalHrs;
   }
window.onload = timecount;

____________

But it shows the summary of all hours or, if I make a search, the summary of the hours of a single user. How can I modify the script, in order to have, as I wrote, a summary of the hours for each student in the view list tab?

Thank you very much for helping me.


NIcola

Average of ratings: -
In reply to Nicola Ribatti

Re: help for javascript code inside db activity

by William Lu -
Picture of Particularly helpful Moodlers

Hi Nicola,

As far as I know, "I make a search, the summary of the hours of a single user." is the best solution.