473,789 Members | 2,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Timer on webpages

Hi,

Im not sure where to find all the documentation i need for this? I need
to timer since a start button has been pushed, and show a counter on a
page. If they click stop i want to keep the time, and carry on
incrementing it if they click start again.

Any suggestions on code, or reference material for this?

Thanks for all the help

David

Apr 29 '06
13 1499
David wrote:
Im not sure where to find all the documentation i need for this? I need
to timer since a start button has been pushed, and show a counter on a
page. If they click stop i want to keep the time, and carry on
incrementing it if they click start again.


<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<style type="text/css" media="all">
.clock {
text-align:center;
font-family: Courier, Courier New;
font-size: 30px;
font-weight: bold;
background-color: white;
border: 0px;
border-style: solid;
border-color: white;
}

body {
background-color: white;
}
</style>
<script language="javas cript" type="text/javascript">

// 1000 = 1 second.
// A reliable 'real seconds' timer is only 1000 (or above)
// on nowadays machines, because CPU will slowdown the
// timer if it are small intervals.
// The lower the value, the longer your 'seconds' will become.
// If the real time is not important for you (you wrote about
// 'a counter'), you can set this value as low as you like.
var interval = 1000;

// These should be left as they are
var tijdID = null;
var tijdLoopt = false;

function stop_klok() {
if (tijdLoopt)
clearTimeout(ti jdID);
tijdLoopt = false;
}

function toon_tijd() {
var now = new Date();
seconden = parseFloat(docu ment.counterfor m.cf.value);
seconden = seconden + 1;
huidigeTijd = '';
if (seconden < 10)
huidigeTijd='00 000'+seconden;
if (seconden < 100 && seconden >= 10)
huidigeTijd='00 00'+seconden;
if (seconden < 1000 && seconden >= 100)
huidigeTijd='00 0'+seconden;
if (seconden < 10000 && seconden >= 1000)
huidigeTijd='00 '+seconden;
if (seconden < 100000 && seconden >= 10000)
huidigeTijd='0' +seconden;
document.counte rform.cf.value = huidigeTijd;
tijdID = setTimeout("too n_tijd()", interval);
tijdLoopt=true;
}

function start_klok() {
stop_klok();
toon_tijd();
}
</script>
</head>

<body>

<form name="counterfo rm">
<center>
<input onFocus="blur() ;" type="text" name="cf"
size="13" class="clock" value="000000">
<br/>
<input type="button" value="Start" onClick="start_ klok();">
<input type="button" value="Stop" onClick="stop_k lok();">

</center>
</form>

</body>
</html>

--
Bart

May 2 '06 #11
Bart Van der Donck wrote:
[...]
var now = new Date();
[...]


No need for that line.

--
Bart

May 2 '06 #12
Dr John Stockton said the following on 5/1/2006 2:11 PM:
JRS: In article <O6************ *************** ***@comcast.com >, dated
Sun, 30 Apr 2006 22:37:29 remote, seen in news:comp.lang. javascript,
Randy Webb <Hi************ @aol.com> posted :
Dr John Stockton said the following on 4/30/2006 5:50 PM:
JRS: In article <EN************ *************** ***@comcast.com >, dated
Sat, 29 Apr 2006 20:56:16 remote, seen in news:comp.lang. javascript,
Randy Webb <Hi************ @aol.com> posted :
Dr John Stockton said the following on 4/29/2006 5:25 PM:
> Using a Date Object naively to indicate duration will be unreliable when
> the season changes between Summer and Winter.
And naively assuming that most business applications are being used on a
Saturday night at 2AM is indeed naive.
It would be; but we should not be concerned just with "most" here; and
it is naive to assume that the clock necessarily changes at 2AM. And this entire scenario falls into the part of my reply that you snipped:

<quote>
If your app is that time critical, then you would know whether that was
happening or not and if you didn't allow for it then you get what you
deserve.
</quote>


Don't assume that questioners and readers are as intelligent as you
think you are.


Coming from someone that is as pedantic as you are, that doesn't bother
me. Try harder.
Then just consider all the Muslim and Jewish businessmen; the businesses
that run 24/7/366; the travellers who keep there portables set to Home
Time, ...

I am not sure what being Muslim or Jewish has to do with that.


Knowing nothing about other cultures is part of being a WASP, no doubt.


Muslim and Jewish is not a "culture", it is a religion. The culture you
are referring to would be Arab (Muslim) and Israeli (Jewish). Practice
what you preach. And, for someone who composes off-line and then posts,
you seem to be pretty lazy and overly fond of unknown acronyms.
FYI, those people do not regard Sunday as the ordained Day of Rest.


Your mastery of the obvious is starting to approach that of TL. Having
lived in an Arab culture for about 2 years, I am well aware of the Holy
Day (It is not an "ordained Day of Rest" to Muslims, it is the Holy Day)
being on Friday (In both cultures). Still, it has nothing to do with
time changing at 2AM in Daylight Savings Time (where practiced).

As in the past, I have told you, stick to Dates and Times, you suck at
common sense John.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 2 '06 #13
JRS: In article <11************ **********@v46g 2000cwv.googleg roups.com>
, dated Tue, 2 May 2006 02:35:36 remote, seen in
news:comp.lang. javascript, Bart Van der Donck <ba**@nijlen.co m> posted :
var interval = 1000; function toon_tijd() {
var now = new Date();
seconden = parseFloat(docu ment.counterfor m.cf.value);
seconden = seconden + 1;
Maybe seconden = +document.count erform.cf.value + 1
huidigeTijd = '';
if (seconden < 10)
huidigeTijd='00 000'+seconden;
if (seconden < 100 && seconden >= 10)
huidigeTijd='00 00'+seconden;
if (seconden < 1000 && seconden >= 100)
huidigeTijd='00 0'+seconden;
if (seconden < 10000 && seconden >= 1000)
huidigeTijd='00 '+seconden;
if (seconden < 100000 && seconden >= 10000)
huidigeTijd='0' +seconden;
document.counte rform.cf.value = huidigeTijd;
tijdID = setTimeout("too n_tijd()", interval);
tijdLoopt=true;
}


It is perhaps better not to use seconden as the name of what is
counted in a VAR interval; I'd use Ticks to be more general, or hard-
code 1000 throughout.

In at least some systems, repeating setTimeout(..., 1000) gives an
average interval of longer than a second, because of overheads and
waiting for the next check. See <URL:http://www.merlyn.demon.co.uk/js-
date0.htm#TaI>.

Consider whether the computer's clock may be adjusted during the
interval, and whether it will matter.

By using new Date() results at the beginning and end of the interval,
you can check your counting (if the clock is not adjusted).

Consider huidigeTijd = String(1e6+seco nden).substring (1)
and
huidigeTijd = seconden + ""
while (huidigeTijd.le ngth<6) huidigeTijd = "0" + huidigeTijd

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
May 2 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
7499
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on it, a frontend and a backend. Case 1: If vba code on the frontend updates many rows (360,000) on the backend, a form's timer event (from the frontend) will stop firing until the user gives the form focus. (Note that the update itself always...
2
1529
by: DaveF | last post by:
I am trying to write a service to fire an ftp object off. I want to wait 2 minutes and then download the files. Then repeat every 2 minutes. The files just seem to stop downloading. Does that timer go off every 2 minutes if the files are done or not? Here is the code: using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics;
9
7288
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null; Let's declare a constant Int32 m_TimePeriod = 10000;
3
2700
by: Yul | last post by:
Hi, We are in the process of designing an ASP.NET app, where a user will enter some 'Customer ID' to be queried in the database. If the ID is valid, several stored procedures will be called to populate multiple webpages containing customer information. There isn't a one-to-one correlation between the stored procedure and a webpage. In other words, a webpage may have to refer to 1 or more DataTables to populate itself. Therefore, a...
12
2808
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown when menu items are clicked.Besides these i would like to put a custom status bar. Any error message encountered in any of the webpage will be displayed in the banner. The problem iam encountering is how to access the customer status bar in child...
2
4067
by: John David Thornton | last post by:
I've got a Windows Service class, and I put a System.Threading.Timer, and I've coded it as shown below. However, when I install the service and then start it in MMC, I get a peculiar message: The MyService service on Local Computer started and then stopped. Some services stop automatically if they ahve no work to do, for example, the Perforamnce Logs and Alert service. I tried switching to a System.Threading.Timer and that didn't work...
12
5535
by: Gina_Marano | last post by:
I have created an array of timers (1-n). At first I just created windows form timers but I read that system timers are better for background work. The timers will just be monitoring different directories and updating a database. No interaction with the GUI. Problem is that the system timers do not have a tag property so I can tie in an object. example (old way):
8
2664
by: =?Utf-8?B?RGF2ZSBCb29rZXI=?= | last post by:
I have a Timer that I set to go off once a day, but it frequently fails! In order to debug I would like to be able to check, at any moment, whether the Timer is enabled and when it will next Elapse. Is there any way -- whether in my code, or in the O/S -- to determine when a Timer is scheduled to Elapse?
16
3258
by: Peter Oliphant | last post by:
Note that although this involves SAPI, it is more a question about Timers and event handlers. I wrote a Speech Recognize handler (SAPI), and put some code in it to enable a Timer. It would not do it. If I bring this same code outside this event handler, it works just fine. Is this normal?
0
9511
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
10412
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
10142
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
9986
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
9021
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
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
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
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.