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

291
Visualizações
How to use setInterval() to call a click function periodically within another function?

this is my first programming in Java. I have two functions, #start and #reset. I want to use setInterval to use #reset function within #start after every 10 seconds.

Here are the two functions. First is #start

$('#start').click(function() {

    // Calculate the amount of time in milliseconds to run for
    var timeleft_s = Math.round(
        parseInt($('#hours'  ).val())*3600 +
        parseInt($('#minutes').val())*60 +
        parseInt($('#seconds').val())*1
    );

    if (timeleft_s > 2147483647) { // Max unsighed 32 bit value
        alert("That's too long. Pick a shorter time.");
        return;
    }

    if (APP.last_sent_status !== null && APP.last_sent_status !== APP.status) {
        return false;
    }

    // 0 : not started
    // 1 : running
    // 2 : stopped
    switch(APP.status) {
        case 0:
            APP.resumeMCA(APP.channel, timeleft_s);
            APP.last_sent_status = 1;
            break
        case 1:
            APP.stopMCA(APP.channel);
            APP.last_sent_status = 2;
            break
        case 2:
            APP.resumeMCA(APP.channel, timeleft_s);
            APP.last_sent_status = 1;
            break
        default:
            break
    }
    APP.updateButtonStates();
});

Here is the reset function

    $('#reset').click(function() {
    APP.resetHistogram(APP.channel);
});

I want to use setInterval inside the start function make sure the reset function executes after every 10 seconds.

Here is what I have tried so far with no luck. Any help is appreciated:

$('#start').click(function() {

    // Calculate the amount of time in milliseconds to run for
    var timeleft_s = Math.round(
        parseInt($('#hours'  ).val())*3600 +
        parseInt($('#minutes').val())*60 +
        parseInt($('#seconds').val())*1
    );

    if (timeleft_s > 2147483647) { // Max unsighed 32 bit value
        alert("That's too long. Pick a shorter time.");
        return;
    }

    if (APP.last_sent_status !== null && APP.last_sent_status !== APP.status) {
        return false;
    }

    // 0 : not started
    // 1 : running
    // 2 : stopped
    switch(APP.status) {
        case 0:
            APP.resumeMCA(APP.channel, timeleft_s);
            APP.last_sent_status = 1;
            break
        case 1:
            APP.stopMCA(APP.channel);
            APP.last_sent_status = 2;
            break
        case 2:
            APP.resumeMCA(APP.channel, timeleft_s);
            APP.last_sent_status = 1;
            break
        default:
            break
    }

 setInterval(#reset,10000)

    APP.updateButtonStates();
});
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

function resetFunction(){
 APP.resetHistogram(APP.channel);
}

$('#reset').click(resetFunction);

then replace

setInterval(#reset,10000) with setInterval(resetFunction,10000)

since you defined the function to be called on #reset click as anonymous there's no reference as such by which you can call it.

so you define it by giving it a name, and then use that in place of onclick function as well as inside your start function

about 4 years ago · Juan Pablo Isaza Relatório

0

I am not totally sure of this answer. If you are trying to start a setInterval inside of the onclick of #start, here's what I think you could do:

 setInterval(() => $("#reset").onclick(),10000);
about 4 years ago · Juan Pablo Isaza Relatório
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