Help - Search - Members - Calendar
Full Version: Countdown Timer
BleepingComputer.com > Software > Programming
   
nixx
hello smile.gif does anybody know how to write an html code for a countdown timer?
i found this one on the net earlier but i think it's in java script (i don't know what the hell i'm talking about here tongue.gif)

<form name="counter"><input type="text" size="8"
name="d2"></form>

<script>
<!--
//
var milisec=0
var seconds=30
document.counter.d2.value='30'

function display(){
if (milisec<=0){
milisec=9
seconds-=1
}
if (seconds<=-1){
milisec=0
seconds+=1
}
else
milisec-=1
document.counter.d2.value=seconds+"."+milisec
setTimeout("display()",100)
}
display()
-->
</script>


well.. it's okay but the problem is, everytime i refresh the page, the countdown resets.
is there anyway for the timer not to reset? like a continuous one? thanks smile.gif
groovicus
It is going to reset each time because the content gets refreshed each time, so the browser is unaware that it has een it before. The only way that I see that is can be done is by determining in the script what time it is relative to the time some event occurs. It makes it more complicated, and somewhat more difficult because there are different time zones to consider. (That code is in javascript, not HTML) You can't do the timer in HTML because HTML has no real logic. It only tells a browser how to display content, and doesn't know anything about the content itself. Sort of like driving a delivery truck in which you have no idea what the contents are in the back. You don't need to know, you just need to get it to where it needs to go.

You will have to use Javascript's date object to query the client's computer to get their timezone offset from GMT. Then you will need a constant to represent your timezone offset from GMT. Then you will need to figure out how to combine those numbers to figure out how many hours you are apart. Once you have their time converted to your time, then your code will figure out how the difference between that time, and the time for which the countdown was intended.

So thinking this through right off the top of my head:
-get client's local time
-get client's time zone offset from GMT
-compare it to your GMT offset.
-convert their time to your time
-compare that time to the time of the event being counted down
-start the timer from there

Actually, that's not at all bad. It could be neatly done in roughly 12 lines of code, plus the other code that you already have. It would take me longer to look up the necessary javascript code than it probably would to code it. Unless you know nothing at all about programming. Then I could see taking a few hours to complete. You could also do it as VBScript, but since you already have the code to display the countdown, you wou just need a method to figure out where the timer should start each time.
nixx
uhm. well unfortunately you're right. i do know nothing about programming. haha anyway, i just want a timer, kinda like a timebomb. coz i'm waiting for something to happen (nothing negative tongue.gif). i just want to put it a website that i visit often so i'd know how much longer i have to wait smile.gif
groovicus
Then your other option is to find bits and pieces of code that will perform bits and pieces of what you want, and tie them together. Or see if you can find someone that will do it for you.
nixx
oh okay. thanks anyway! smile.gif
groovicus
I know its not very helpful, but if you search enough, you may find what you need.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.