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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:13:11+00:00 2026-05-28T03:13:11+00:00

I am working with Javascript StopWatch in C# web Aplication. But I don’t get

  • 0

I am working with Javascript StopWatch in C# web Aplication. But I don’t get output from javascript. Below is my code.

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <script type="text/javascript" language="JavaScript">
            var state = 0;
            function startstop() {
                if (state == 0) {
                    state = 1;
                    then = new Date();
                    then.setTime(then.getTime() - ms);
                } else {
                    state = 0;
                    now = new Date();
                    ms = now.getTime() - then.getTime();
                    document.stpw.time.value = ms;
                }
            }
            function swreset() {
                state = 0;
                ms = 0;
                document.stpw.time.value = ms;
            }
            function display() {
                setTimeout("display();", 50);
                if (state == 1)  {now = new Date();
                ms = now.getTime() - then.getTime();
                document.stpw.time.value = ms;
            }
        }
        </script>
    </head>
    <body onload="display()">
        <form id="form1" runat="server">
            <div>
                Time:
                <input type="text" name="time"/>
                <input type="button" name="ssbutton" value="Start/Stop"    onclick="javascript:startstop()"/>
                <input type="button" name="reset" value="Reset" onclick="javascript:swreset()"/>

            </div>
        </form>
    </body>
</html>

I am new with javascript ,Where I am doing mistake?? Thank You…

Udate:Finally I get the errors and solved it. Here is updates solution for someone who want to implement JavaScript Stopwatch in C# Application.

 <html>
 <head>
 <script type="text/javascript">
 var ms = 0;
 var state = 0;
 var then;
 var now;
 ms = new Date();
 function startstop() 
 {

     if (state == 0) 
     {
         state = 1;
         then = new Date();
         then.setTime(then.getTime() - ms);
     }
     else
      {
         state = 0;
         now = new Date();
         ms = now.getTime() - then.getTime();
         document.getElementById('timeInput').value = ms;
     }
 }
 function swreset() {
     state = 0;
     ms = 0;
     document.getElementById('timeInput').value = ms;
 }
 function display() {
     ms = new Date();

     setTimeout("display();", 50);
     if (state == 1) {
                      now = new Date();
                      ms = now.getTime()-then.getTime();
                      document.getElementById('timeInput').value = ms;
     }
     }
 </script>
 </head>
 <body onload="display()">
 <form>
    Time:
    <input type="text" name="time" id="timeInput"/>
    <input type="button" name="ssbutton" value="Start/Stop" onclick="javascript:startstop()"/>
    <input type="button" name="reset" value="Reset" onclick="javascript:swreset()"/>



</form>
</body>
</html>

Thanks For All your help.

  • 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-28T03:13:11+00:00Added an answer on May 28, 2026 at 3:13 am

    Here are some first steps: (This doesn’t mean that everything will work, but it will sure help.)

    • As JohnFx pointed out, make sure the HTML is in good shape.
    • Give your “text” input called “time” an ID.
      <input type="text" name="time" id="timeInput"/>
    • Reference the element using getElementById()
      document.getElementById("timeInput").value = ...
    • If things don’t behave properly, put alert(...) statements in the javascript to see where its going and what values it’s coming up with.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to get some simple javascript working in gwt but keep failing. The
I'm trying to get a case-insensitive search with two strings in JavaScript working. Normally
I now have a working JavaScript autocomplete function, thanks to help from many of
I have some working Javascript code that generates an RDF/XML document using variables picked
How would I get the current URL with a javascript code that could be
Why this javascript working fine in Firefox but not in IE 6 and 7
How can I transform the following jQuery code to working JavaScript code? jQuery $('select
Working with JavaScript in IE, I used the reflected property but the problem is
I've been working with javascript for a while but never made any classes and
I am working with JavaScript date's being returned from ASP.net which is of course

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.