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

173
Views
Function is automatically started without clicking the button

Whenever I am loading the page, the function is starting automatically, without even clicking on the button.

btn1 = document.getElementById('btn1');
btn1.addEventListener("click", getTime(1,0));

I have taken the button id to a new variable, and then added (addEventlistener) on click, but whenever I am reloading the page, the function getTime() is automatically started.

function getTime(x,y){
    text = document.getElementById('timer-text');
    text.innerHTML = 'Started';

    var min = x;
    var sec = y;
    total_time = (min*60) + sec;
    setInterval(()=>{
        timerText = document.getElementById('timer-text');
        if(total_time<=0){
            timerText.innerHTML = 'TIME OUT!';
            clearInterval();
            return;
        }
        let minText = Math.floor(total_time/60);
        if(minText<10){
            minText = '0' + minText;
        }
        let secText = (total_time%60);
        if(secText<10){
            secText = '0'+secText;
        }
        timerText.innerHTML = minText +" : "+ secText;
        total_time = total_time - 1;

    }, 1000)
}
about 4 years ago · Juan Pablo Isaza
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!