Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda