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

  • Home
  • SEARCH
  • 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 8878363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:41:39+00:00 2026-06-14T19:41:39+00:00

I have a little fiddle here where I’m starting/stopping/resetting a javascript timer. The functionality

  • 0

I have a little fiddle here where I’m starting/stopping/resetting a javascript timer.

The functionality needs to be a timer runs on a page. When the timer is up, it sends a message, then restarts. The stop button will stop the timer completely.

The fiddle above has the functionality I just described, however I feel like I’m not doing this correctly. Is setTimeout the correct way to create this timer? Should I use setInterval instead?

Secondly, my reset code looks like :

var onReset = function() {
        clearTimeout(timerHandle);
        onStart();    
};

Is there a more elegant way to reset a timer in javascript?

Thanks.

  • 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-14T19:41:41+00:00Added an answer on June 14, 2026 at 7:41 pm

    The only improvement I can offer is for you to put it all in an encapsulated object, ask if you want an example. Or if you want to keep the structure you’ve got then change your onStart function to this to remove a bit of un-needed code.

    var onStart = function() {
    
        timerHandle = setInterval(function() {
            $("#console").append("timer fired.. <br />");
        }, 2000);
    
    };
    

    Fiddle here http://jsfiddle.net/qx6CM/

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

Sidebar

Related Questions

I have this annoying little bit of spacing I can't remove. Here's a fiddle.
Given this little fiddle: http://jsfiddle.net/5Sw3h/8/ I have a navigation panel to the left, a
I have a little experience with Zend Framework, but I like to fiddle with
enter code here I am having a little problem with jquery.empty(). I have some
Fiddle here: http://jsfiddle.net/emJcx/1/ I have a drop down menu that is a simple show
I have a list with a list image of a little plus sign. Here
http://jsfiddle.net/sMMHW/ In the fiddle above I have a small little red 1 pixel line
I have little unusual problem to solve. I need some hint or links to
I have little bit longer question for you - but hope answer will be
I have little question about how web browser retrieve webpage? I know this User

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.