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 7809481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:26:59+00:00 2026-06-02T03:26:59+00:00

I want to count down from 10 seconds to 0. When it have reached

  • 0

I want to count down from 10 seconds to 0. When it have reached 0 the DIV will reload and the timer will start over again. I have this function that allows it to do exactly like I wanted but the problem is that when the countdown have reached 0 and going back to 10, it will count -1 reload -2 reload -3 reload -4 reload and so on. That is not how I want it! 🙂

Here’s my code:

var time = setInterval(countdown, 1000);
function countdown() {
    var count = 10;
    countdown = setInterval(function() {
        $('#countdown').html(count + ' sekunder kvar');

        if(count == 0) {
            $('#weather-data').load('jquery-fetch/fetch-weatherdata.php?place=' + myplace);
            clearInterval(countdown);
        }

        count--;
    }, 1000);
}

How can I fix my problem so the timer counts down from 10 to 0 and repeat that countdown forever?

Thanks in advance.

EDIT

When this function has reached 0 for the first time and starts over, it counts like this: 10, 9, 8, 10, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 10, 6, 5, 4, 3, 2, 1, 10, 9, 8, 10, 7, 6, and so on. Why does it act like this with this code?

function countdown() {
    var count = 10;
    var timerId = setInterval(function() {
        $('#countdown').html(count + ' sekunder kvar');
        count--;

        if(count == 0) {
            $('#weather-data').load('jquery-fetch/fetch-weatherdata.php?place=' + myplace);
            clearInterval(timerId);
            countdown();
        }
    }, 1000);
}

countdown();

Thanks in advance!

  • 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-06-02T03:27:00+00:00Added an answer on June 2, 2026 at 3:27 am

    I see a lot of problems in your script… So not sure how you even get that to work..

    1. Function name can’t have -, so that call won’t work :S
    2. countdown is a global variable inside your function countdown() which is the same as your function name, effectively a countdownception
    3. You are effectively creating a new Interval every one second as you are calling countdown

    To achieve what you want, try the simpler:

    function countdown() {
        // your code goes here
        var count = 10;
        var timerId = setInterval(function() {
            count--;
            console.log(count);
    
            if(count == 0) {
                // your code goes here
                count = 10;
            }
        }, 1000);
    }
    
    countdown();
    

    http://jsfiddle.net/Xrbm5/13/

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

Sidebar

Related Questions

I want to have a counter that counts down from 60 seconds to 0.
My timer counts down from 60 to zero . I want my movie to
I have a jquery timer on my page that counts down from 10 to
I want to count how many times i built on VS.NET . I have
I want to count the number of accounts from the resulting table generated from
I am writing a count down timer, using .postdelayed(), that speaks each second as
In my application, I have a recent files drop down menu. It will contain
I am trying to make a timer for my game that counts down from
I have a timer thread that executes five seconds in the future and a
I have an auction site that has a javascript timer counting down. For some

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.