Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5981273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:55:16+00:00 2026-05-22T21:55:16+00:00

can anyone see what is wrong with the following code. it’s supposed to display

  • 0

can anyone see what is wrong with the following code. it’s supposed to display a count down from 30 and afterwards it refreshes the page with jquery’s ajax load() function.

it works fine for the first or second count down but then the timer starts too count down to fastand sometimes goes to the negative numbers and does not stop at all

what am i doing wrong?

function refreshPage(){
    stopRefresh();
    $('div.yui-content').load('rdPage.aspx div.yui-content', doCalculation);
}

function stopRefresh(){
    clearTimeout(timer);
    clearTimeout(interval);
}

var count, timer, interval;

function startTimer(){
    count = 30;
    timer = setTimeout(refreshPage,count * 1000);
    interval= setInterval(updateTimer,1000);
}
function updateTimer(){
    count --;
    $('#timerSpan').text("Refreshing in " + count + "s");
}


function doCalculation(){
    negativeNumberRed();
    startTimer();

}

edit: added doCalculations()

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:55:17+00:00Added an answer on May 22, 2026 at 9:55 pm

    Add a call to “stopRefresh()” to the “startTimer()” call.

    function startTimer(){
        stopRefresh();
        count = 30;
        timer = setTimeout(refreshPage,count * 1000);
        interval= setInterval(updateTimer,1000);
    }
    

    My guess is that your code is managing to start up more than one instance of the interval timer. They’ll all decrement the same counter.

    edit — oops – Dr. Strangelove is correct – you need to use “clearInterval()” on interval timers, and “clearTimeout()” for timeout timers. (edit again well, you probably should do that, but Chrome at least seems to stop interval timers via “clearTimeout()”. Here is the jsfiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone see whats wrong with either the code to grab the XML or
Does anyone know how I can check to see if a directory is writeable
Does anyone have experience using the URL Rewrite Module (see here )? Can it
Can anyone tell me how I can display a status message like 12 seconds
Can anyone point me in the right direction on this. From reading the FAQs
I've got the following code that I'm using to get a html page. Make
The following code throws an exception which I have no idea what goes wrong
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
Can anyone recommend a good library for generating an audio file, such as mp3,
Can anyone recommend some good resources that highlight the differences between Oracle and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.