Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Countdown Timer


  • Please log in to reply
5 replies to this topic

#1 nixx

nixx

  • Members
  • 159 posts
  • OFFLINE
  •  
  • Local time:05:03 PM

Posted 19 April 2006 - 09:49 PM

hello :thumbsup: 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 :flowers:)

<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 :trumpet:

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:03:03 AM

Posted 20 April 2006 - 08:55 AM

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.

#3 nixx

nixx
  • Topic Starter

  • Members
  • 159 posts
  • OFFLINE
  •  
  • Local time:05:03 PM

Posted 20 April 2006 - 09:03 AM

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 :thumbsup:). i just want to put it a website that i visit often so i'd know how much longer i have to wait :flowers:

#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:03:03 AM

Posted 20 April 2006 - 09:12 AM

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.

#5 nixx

nixx
  • Topic Starter

  • Members
  • 159 posts
  • OFFLINE
  •  
  • Local time:05:03 PM

Posted 20 April 2006 - 11:04 PM

oh okay. thanks anyway! :thumbsup:

#6 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:03:03 AM

Posted 21 April 2006 - 12:39 AM

I know its not very helpful, but if you search enough, you may find what you need.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users