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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:36:32+00:00 2026-05-29T16:36:32+00:00

When I press the button onces, I want to start count, and when I

  • 0

When I press the button onces, I want to start count, and when I press again to stop count. I know that to work two functions with one button onclick event, it is seperate with “;”. Any suggestion? This code works well with two buttons each for one function.
Thanks in advance.

<form>
<input type="button" value="Start count!" onclick="doTimer();stopCount();" />
</form>

javascript code:

var c=0;
var t;
var timer_is_on=0;

function timedCount()
{
document.getElementById('txt').value=c;
c=c+1;
t=setTimeout("timedCount()",1000);
}

function doTimer()
{
if (!timer_is_on)
{
timer_is_on=1;
timedCount();
}
}

function stopCount()
{
clearTimeout(t);
timer_is_on=0;
}
  • 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-29T16:36:35+00:00Added an answer on May 29, 2026 at 4:36 pm

    Here’s my untested solution with a few tips thrown in for good measure.

    First, I think you can probably get rid of the <form> and </form> tags.

    Second, you may find it helpful to give your variables meaningful names, not just c or t

    Third, change timer is on to a boolean: var timer_is_on = false;

    Fouth change the button to this: <input type="button" value="Start count!" onclick="doTimer();" />

    Fifth replace your code with this:

    function doTimer(){
    
      if( timer_is_on ){
    
        // Code to start the timer
        // and any other code you want
    
        timer_is_on = false;
    
      }else{
    
        // Code to stop the timer
        // and any other code you want
    
        timer_is_on = true;
    
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to fill-out a form automatically and press a button on that form
I'm trying to get a specific asp:button onclick event to fire when I press
I have an image that is animating, until you press the button that says
I have a grid and a button. I want to be able to press
I want to be able to control certain functions when a button is clicked
I want to be able to press a button on my program and hold
How do I detect a button press on a USB gamepad on OSX 10.5
I have a form where you may press a button which will give you
How can I flip an NSWindow so I can press a button, and the
I've got a save dialog box which pops up when i press a button.

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.