Petro
Petro

Reputation: 3652

Incrementing a setInterval() value from a global

I'm trying to increment the timeout on either setInterval, or setTimout. However, my global is not working. I'm not to familiar with javascript. Please help!

//What I'm trying to do:

  $(document).ready(function() {
    var joeIncrement=1;
    setInterval(function() {
    joeIncrement++;
    $('#comment_counter').load('get_commentcount.php');
    }, 15000*joeIncrement);
});

Upvotes: 0

Views: 177

Answers (1)

nilgun
nilgun

Reputation: 10629

$(document).ready(function() {
    var joeIncrement=1;
    var interval = function(){
        setTimeout(function() {
            joeIncrement++;
            $('#comment_counter').load('get_commentcount.php');
            interval();
        }, 15000*joeIncrement);
    }
    interval(joeIncrement)
});

Upvotes: 2

Related Questions