Display countdown

M

Michael

I would like to display the time counting down on a webpage when I use this
script.... Is it possible?

<script language="JavaScript">
<!--

var tID = 0;
var startTime = null;

var timeout=20*(60*1000) + 0*1000; // 20:00 minutes, as milliseconds

function UpdateTimer() {
if(tID) {
clearTimeout(tID);
}
var date = new Date();
var diff = date.getTime() - startTime.getTime();
if (diff >= timeout) {
focus();
window.open('/timeout.htm',"timeout",'toolbar=0,location=0,directories=0,sta
tus=0,menubar=0,scrollbars=0,resizable=0,width=400,height=200');

} else {
tID = setTimeout("UpdateTimer()", 1000);
}
}
function Start() {
startTime = new Date();
tID = setTimeout("UpdateTimer()", 1000);
}
// -->
</script>
 
D

Dr John Stockton

JRS: In article <0jjyc.9756$eu.831@attbi_s02>, seen in
news:comp.lang.javascript said:
I would like to display the time counting down on a webpage when I use this
script.... Is it possible?

Since Number 3 page of the set referred to in the regularly-posted
newsgroup FAQ has a countdown until next Christmas noon, I suppose that
it must be. See signature.

<script language="JavaScript">
Deprecated ; should be said:
Not inevitably superfluous.

tID = setTimeout("UpdateTimer()", 1000);

That will give a delay of 1000 ms plus overheads; some seconds will be
missed on at least some systems. It is surprisingly easy to recompute
the delay every time.
 
M

Michael

Thank you Dr. Spock, but your convoluted answer, really isn't one.

Michael

--

(remove SPAMBLOCK if replying by e-mail)
Dr John Stockton said:
JRS: In article <0jjyc.9756$eu.831@attbi_s02>, seen in


Since Number 3 page of the set referred to in the regularly-posted
newsgroup FAQ has a countdown until next Christmas noon, I suppose that
it must be. See signature.



Not inevitably superfluous.



That will give a delay of 1000 ms plus overheads; some seconds will be
missed on at least some systems. It is surprisingly easy to recompute
the delay every time.
links.
 
L

Lee

Michael said:
Thank you Dr. Spock, but your convoluted answer, really isn't one.

He answered your question and, in addition, directed
you to an example and lots of useful information, and
also suggested improvements to your code.

If what you really wanted was for somebody to make the
changes to your code, you should have said so, and you
certainly should have responded more politely.
 
M

Michael

A question can be answered in a tone that any receiver can feel as though
they are being helped. In this case he came across not as helpful but
condescending.

I do not argue semantics but "...when I use this script.... Is it
possible?", is a statement that implies that I was talking about still using
the script, but just displaying it counting down. If I needed to be more
clear he could have replied as such with conversational English...

Michael


--
 
D

Dr John Stockton

JRS: In article <cbazc.49050$Sw.48757@attbi_s51>, seen in
news:comp.lang.javascript said:
A question can be answered in a tone that any receiver can feel as though
they are being helped. In this case he came across not as helpful but
condescending.

I do not argue semantics but "...when I use this script.... Is it
possible?", is a statement that implies that I was talking about still using
the script, but just displaying it counting down. If I needed to be more
clear he could have replied as such with conversational English...

Responses should go after trimmed quotes; evidently you have not yet
managed to study the newsgroup FAQ adequately.

If you post here, you need to realise that you are likely to be answered
in English. That is a language developed in my country; one which is
capable of exact expression (particularly when used by Dutch & Danes).
It is not, however, the American language, and you must learn to get
used to the difference (I suppose you are a Murican; your post gives no
positive indication, but most who are not choose to show that they are
not) in style.

The code that you posted cannot be used to give the desired effect; it
has a grammatical error due to your carelessness in posting. You have
allowed your posting agent to introduce a line break, which falls within
a string. When code is posted, it is for the poster to see that it will
be transmitted in executable form; your readers should not have to waste
time in sorting out superfluous adventitious deficiencies.

The code that you apparently tried is inadequate to give the desired
effect. It declares variables and functions, but calls for no
perceptible action.

If function Start is actually called, function UpdateTimer is (for no
obvious reason) called nearly once per second; and after 20 minutes it
attempts to open a window showing page /timeout.htm whatever that may
be. It is pointless to test with 20 minutes when 3 seconds will
obviously exercise all the code. Changing /timeout.htm to the name of a
page that I have, it does get loaded. (BTW, it would be slightly more
efficient to calculate the finish time only once, in function Start.)

But to display the time counting down on a Web page (well, you cannot,
since the time always increases; but I suppose you mean the interval
remaining until some future event), you either can follow the advice
previously given; or you can throw away most of your existing code and
ask again, stating your wishes more appropriately.

The task smells of being a piece set as coursework by a mediocre
educational institution.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top