Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda