www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] unable to get this timer script to work

  1. #1
    Join Date
    Aug 2010
    Posts
    12

    resolved [RESOLVED] unable to get this timer script to work

    I am making an online exam and want to incorporate the timer script given in the link below.I have incorparated the script in an html file written below but the timer doesn't show up when I run the html file.Assuming the timer script is correct,can anyone tell me what I am doing wrong here.Am I calling the timer script incorrectly or something?


    This is the timer script
    http://svn.terracotta.org/svn/forge/...s/examTimer.js


    This is my html file


    <HTML>
    <HEAD>


    <SCRIPT>
    //The exact script from the above site is given in bold here
    //There is probably not an error with the script given in bold
    var hour = 0;
    var mins = 0;
    var secs = 0;

    function initializeExamTimer(remainingTimeInSeconds) {
    hour = Math.floor(Math.max(remainingTimeInSeconds/(60*60), 0));
    var secsLeft = remainingTimeInSeconds % (60*60);
    mins = Math.floor(Math.max(secsLeft/60, 0));
    secsLeft = secsLeft % 60;
    secs = secsLeft;
    displayRemainingTime();
    setTimeout("updateRemainingTime()", 1000);
    }

    function updateRemainingTime() {
    var examFinished = false;
    if (secs > 0) secs--;
    else {
    if (mins > 0) {
    secs = 59;
    mins--;
    }
    else {
    if (hour > 0) {
    secs = 59;
    mins = 59;
    hour--;
    }
    else {
    hour = min = sec = 0;
    examTimedOut();
    examFinished = true;
    }
    }
    }
    displayRemainingTime();
    if (!examFinished) setTimeout("updateRemainingTime()", 1000);
    }

    function displayRemainingTime() {
    var hourStr = hour < 10? "0" + hour: hour;
    var minsStr = mins < 10? "0" + mins: mins;
    var secsStr = secs < 10? "0" + secs: secs;
    var time = hourStr + ":" + minsStr + ":" + secsStr;
    var remainingTimeSpan = document.getElementById('remainingTime');
    remainingTimeSpan.innerHTML = time;
    }

    function examTimedOut() {
    this.document.examForm.submit();
    }

    </SCRIPT>
    </HEAD>

    <BODY>

    <script>
    initializeExamTimer(4000);
    </script>
    </BODY>
    </HTML>

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    <BODY>
    <span id="remainingTime"></span>
    <script>
    initializeExamTimer(4000);
    </script>
    </BODY>
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Aug 2010
    Posts
    12
    Awesome,
    Thanks a lot.It is working now

    I could never have figured that out.

    While it isn't necessary,it would be interesting if someone could explain why the above method of including
    <span id="remainingTime"></span>


    worked.By the way,Fang,kudos to you.

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    That's the element the script writes the time to.
    At least 98% of internet users' DNA is identical to that of chimpanzees

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles