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

288
Views
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 answers
Answer question

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 Report

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 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!