JennyWren
06-11-2008 22:29:25
I'd like to design a webpage where you can enter some values, eg 300, 230, 215, 200, 100 and a timer starts ticking down from the first number to 0, announcing each time it hits a number. Anyone know if there is a way to generate a PHP or Javascript timer which runs in real-time seconds and can count down (and also have some audio cues?).
For those who are interested, I've recently gotten into freediving and I'm looking to rewrite a little java applet which does basically this (although the times are preset). These tools are used to build up tolerances to high levels of carbon dioxide and low levels of oxygen (google CO2 and O2 tables).
dmorris68
07-11-2008 05:55:50
Freediving? Brave girl!
Sure, it's possible. Have you ever done Javascript timers? Just dynamically create multiple timout events that fire according to your schedule. Each event could point to the same handler which would trigger any audio/visual cues. Or create a single timeout event that resets itself for the next interval by indexing over an array of intervals. In my mind this should be easy.
http//www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/
JennyWren
07-11-2008 08:36:43
That looks like it should do the trick. I was hoping to avoid Javascript, but there's no time like the present to improve my limited JS skills.
Yeah, freediving is amazing, I just started (took a course) and got down to 93 feet the other day. It's sooooo fun.
dmorris68
07-11-2008 11:44:56
Something like this pretty much demands client side code, which means Javascript. You could, in theory, do it on the server, but it would be clunky and inaccurate -- the network latency (particularly across the internet) would play havoc with timer accuracy. You'd either have to refresh the page regularly, or implement some AJAX calls (again, using Javascript) to have the server update a sub-section of the page without reloading.
So yeah, simple JS timeouts make a lot more sense for this.