Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
Click on a button and start Time counting on redirected page (JavaScript)

I am trying to develop a quiz app with Django. Where I want to add a functionality like this - "When the users will click on start test button, they will be redirected to the questions page, and exam time will be started". Here I am using JavaScript "setInterval" to count time. It's working on the same page, but it's not working on the redirected page.

My Js code :

var check = null;

function printDuration() {
    if (check == null) {
        var cnt = 0;

        check = setInterval(function () {
            cnt += 1;
            document.getElementById("para").innerHTML = cnt;
        }, 1000);
    }
}

function stop() {
    clearInterval(check);
    check = null;
    document.getElementById("para").innerHTML = '0';
}

console.log("Time counting... ... ...")

Button

<a href="{% url 'test' %}" class="btn btn-primary mt-5"id="btnStart" type="button" value="Start"
    onclick="printDuration();">Start Test</a>

Redirected page code: , here time counting will be started:

<h2 class="pb-5">Welcome to test page</h2>
    <p id="para">0</p>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If I understand correctly, the timer is on the page before redirect. When you go to a new url, everything reloads including the JavaScript. Everything from the previous page including your timer is removed. You'll have to make a new timer in the redirected page

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!