Retrieve TOC completed pages into variable

tkosker1029
tkosker1029 Community Member Posts: 26
Hello All

Does anyone have a  code sample of a javascript to retrieve completed / incompleted page count into a variable from TOC content without using LMS or scorm?

 

I will appreciate if you can share any sample doing this.

 

Regards

Comments

  • tkosker1029
    tkosker1029 Community Member Posts: 26
    Just a quick note I need to count the pages which belongs to chapters as completed
  • pjackson2462
    pjackson2462 Community Member Posts: 69 ☆ Roadie ☆
    G'day Tamer,

    pageStatus = trivPageTracking.GetRangeStatus(pageNumber);

    This will return "complete" or "notstarted", the pageNumber would start at 1 and end with the number of pages you have in the title.  The number of pages in a give chapter is in the TOC but you need a lot of work to get at it, I suggest that you simple take note of the start and end page numbers of each of the chapters and hard wire these for each title, not the best solution but it will work.

    HTH

    Regards, Peter
  • tkosker1029
    tkosker1029 Community Member Posts: 26
    Thanks for your suggestion. I just created 10 empty pages and a TOC and run JS as follows :

    cNum=0;
    cNum2=0;
    for (i = 1; i < 11; i++) {
    pageStatus="incomplete";
    pageStatus = trivPageTracking.GetRangeStatus(i);
    if (pageStatus==="complete") {
    cNum=cNum+1;
    }
    }
    Varpagecount.set(cNum);

     

    but this does not return correct number of completed pages. I am new in JS so I might have mistake.

     
  • pjackson2462
    pjackson2462 Community Member Posts: 69 ☆ Roadie ☆
    G'day Tamer,

    Well done on the JavaScript, I made some changes, try the following:

    var cNum=0;
    var status='';
    for (i=1; i<11;i++){
    pageStatus = trivPageTracking.GetRangeStatus(i);
    status+= i + ' ' + pageStatus + ' ';
    if (pageStatus=='complete') {
    cNum += cNum;
    }
    }
    alert(cNum + ' ' + status);

    You had 3 '=' equals in the "if" line.

    If you add a TOC that shows pages visited then the count should be the same as what the TOC displays.  You will need to clear your cache as each time you launch the page visited data is stored in your cache.

    HTH
  • tkosker1029
    tkosker1029 Community Member Posts: 26
    Hi Peter,

    I have tried it but no luck. I have used the code as follows and you can see the result in screenshot I attached. What can be the issue I am missing?

    var cNum=0;
    var status="";
    for (i=1; i<11;i++){
    pageStatus = trivPageTracking.GetRangeStatus(i);
    status+= i + " " + pageStatus + " ";
    if (pageStatus=="complete") {
    cNum += cNum;
    }
    }
    alert(cNum + " " + status);
  • pjackson2462
    pjackson2462 Community Member Posts: 69 ☆ Roadie ☆
    I'm really sorry, I have cNum += cNum; it should be cNum += 1;

    That said, I don't know why your TOC shows that pages completed with the function are not completed in the TOC.  I don't know how this is possible as it works perfect for me, sorry about that.

    Regards, Peter
  • tkosker1029
    tkosker1029 Community Member Posts: 26
    Hi Peter

    I am also shocked why I am getting these random results. There might be a solution but we two are not enough to solve this I think.

    Thanks for your help.

    Kind Regards
  • agaudet1236
    agaudet1236 Community Member Posts: 36
    So i just gave the script a try everything looks good with it.

    However one thing to notice is that this uses a cookie system to track page visitation and display it correctly. If you are in publish preview mode there is the possibility of the status being cached already, which  I ran into when  i visited each page it stored the "complete" status for the page so when i went to "test" it again that value was already complete

    Doing a full publish and storing it on my local webserver and re checking your script there It worked as intended displaying the first page as in progress and each remaining as not started.

    That would explain the random behavior when the script is pretty straight forward. To test it correctly deleting the cookie/clearing your cache between visits is a must to see the correct output.
  • klaatu
    klaatu Community Member Posts: 988
    ...disregard
Sign In or Register to comment.

So You Wanna Be An eLearning ROCKSTAR?

We're all fans of eLearning here! Want to become an eLearning ROCKSTAR? Just click on one of the buttons below to start your rocking journey!