473,769 Members | 6,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Resetting my Stop watch

12 New Member
I wrote this program. Its kinda of strange when I make a reset function reset(){c=0} its doest reset the setTimeout. However if I directly pass c=0 to the onclick button it does reset the timer. What is the logic of this?
Here is the program:


[HTML]<html>
<head>
<script type="text/javascript">
var c=0;
var t;
function timedCount()
{
document.getEle mentById('txt') .value=c;
c=c+1;
t=setTimeout("t imedCount()",10 00);
}

function stopCount()
{
clearTimeout(t) ;
}

function reset()
{
c=0;

}

</script>
</head>

<body>
<form>
<input type="button" value="Start count!" onClick="timedC ount()">
<input type="text" id="txt">
<input type="button" value="Stop count!" onClick="stopCo unt()">

//Problem Area---------------------------------------------------------------------

<input type="button" value="reset!" onClick="reset( );">// if I pass "c=0" it works
//yet if I call the reset function which sets c=0 it doesnt work Why?

</form>

//-----------------------------------------------------------------------------------------------------

<p>
Click on the "Start count!" button above to start the timer. The input field will count forever, starting at 0. Click on the "Stop count!" button to stop the counting.
</p>
</body>

</html>[/HTML]
Oct 23 '08 #1
4 2094
acoder
16,027 Recognized Expert Moderator MVP
See this similar recent thread.
Oct 24 '08 #2
Rajneesh Chellapilla
12 New Member
My question isnt a coding question as much as a logic question. Basically I want to know why: does setting c=0 in the onclick function produce a different result than writing a function reset() {c=0} and inserting the reset() function into onclick.

Setting c=0 in onlclick makes it work button works. However when I put the function reset() it just clears the field but does not restart the timer. Instead the timer continues where it left off. Here is the exact code, scroll to near the bottom to see what I am talking about I put comment lines.

[HTML]<html>
<head>
<script type="text/javascript">
var c=0;

var d=15001;
var e=19182;
var t;



function timedCount()
{
String.fromChar Code(c)

document.getEle mentById('txt') .value=String.f romCharCode(c);
document.getEle mentById('text' ).value=c;
c=(c+1);
d=(d+1);
e=(e+1);
t=setTimeout("t imedCount()",1) ;

}



function stopCount()
{
clearTimeout(t) ;
}




function reset()
{
c=0;

}


</script>












<style type="text/css">

.style1 {
font-family: ;
font-size: 60px;
color: rgb(0,100,175);
background-color: #FFFFCC;
padding: 2px;
height: 80px;
width: 100px;
border: 1px solid #7F9DB9;
}

.style2 {
font-family: ;
font-size: 60px;
color: rgb(0,100,175);
background-color: #FFFFCC;
padding: 2px;
height: 80px;
width: 100px;
border: 1px solid #7F9DB9;
}




</style>




</head>

<body>
For God who inspires
<form>
<input type="button" value="Start Count" onClick="timedC ount()">


<input type="text" class="style1" id='txt'><br></br>

<input type="button" value="Stop count!" onClick="stopCo unt()">
<input type="button" value="reset" onClick="c=0;">//this works
//however this does not:
//<input type="button" value="reset" onClick="reset( )"> does Not work
//my qestion is why?
<input type="text" class="style2" id='text'>



</form>

<br></br>
<br></br>
<br></br>
<p>Click on the button above. The the imput will start counting throgh various unicode characters.</p>
</body>

</html>[/HTML]
Oct 24 '08 #3
zaphod42
55 New Member
reset it a reserved keyword:) try "resetC()" instead, I just tested it and it worked fine:)
Oct 24 '08 #4
Rajneesh Chellapilla
12 New Member
Thank you for your help. I will try it my self. I am new to Javascript and programming and I appreciate you taking the time to help me.
Oct 25 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
18769
by: riprod | last post by:
Someone in the IIS newsgroup suggest I post this here, so sorry in advance for the cross posting. I have a Win 2003 SP1 with IIS 6 and host about 40 websites, most of them useing ASP/VB with access databases. The server is a Dell Dual 2.4Ghz XEON with 512Mb Ram. Every few days I get the error 'HTTP/1.1 New Session Failed' and the server stops showing the sites. It comes right after a bit and then the error comes back. I
4
9118
by: Richard Haygreen | last post by:
I have an HTML form which includes a combo box with 4 options, which is used to select a method of contact (phone, email etc...). If the user selects an invalid option (for example, they have selected phone, but have not supplied a phone number) an alert box pops up. How do I reset the combo box so it displays the first option in the combo box (which is the default)?? Many thanks in advance.
2
5580
by: Job Lot | last post by:
how can i create a stop watch using vb.net i am performing a data extraction job using windows forms and want to display time elapsed on the form. how can i do it? Thanks
8
3521
by: Matt Theule | last post by:
While stepping through an ASP.NET project, I found that data was being inserted into my database even though I was not stepping through the code that inserted the data. I have a single page with inline code. The page has a Datagrid, a textbox and a button. When the button is clicked, the value of the textbox is inserted into the table whose contents are displayed on the page. The problem occurs when I set a breakpoint on a line *IN*...
8
1301
by: Rob Bazinet | last post by:
Hello all; I have an ASP.NET application which I run part of it in a new thread. The part running is very processor and time intensive and takes an hour plus to complete. The problem I am experiencing is after the thread has been running for about 20 min it stops. I am running this app on a Windows 2003 server and SQL Server 2000 on the backend. I suspect it may be a SessionState time out issue and I have played with the settings...
4
4084
by: Ian Davies | last post by:
Hello I am struggling for a solution to clear some fields on my webpage that takes their values from some sessions My solution below works when the button is clicked twice. I sort of know why I have to click it twice to do the job (the first submit resets the sessions but this it too late to change the field values, which requires another submit to pick up the new session values). Problem is I cant think how to accomplish the resetting of...
2
1645
by: tshad | last post by:
I have my Application variables getting set in my Global.aspx file. If I change a variable in my table that is read at startup, I need to restart the application to reload the variables. I found, however, that if I stop and start the Application from IIS, it doesn't reload the data. I need to actually stop and start the Web Service (World Wide Web Publishing) to get it to work.
3
2709
by: GiJeet | last post by:
I put the the button property in the watch window but it doesn't stop when the property changes value. For example I put this.myButton.Visible in the watch window with an initial value of false and I want program execution to stop when the Visible property changes to true. how to accomplish this? TIA G
11
3742
by: uzairmemon | last post by:
Any one Have coding of Reverse stop watch?
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.