473,386 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Run code at different periods of time

4
How can i do an non intrusive alarm at different period of time before the test ended? Like a music is played 15mins before the test ended.

Expand|Select|Wrap|Line Numbers
  1. <script type ="text/javascript">
  2.  
  3. var dStopTime = new Date();
  4. dStopTime.setHours(dStopTime.getHours(),dStopTime. getMinutes()+20,dStopTime.getSeconds());
  5. var clockID = 0;
  6. function UpdateClock() {
  7. if(clockID) {
  8. clearTimeout(clockID);
  9. clockID = 0;
  10. }
  11. var dNow = new Date();
  12. if(dNow<dStopTime) {
  13. dNow.setHours(dStopTime.getHours()-dNow.getHours(),dStopTime.getMinutes()-dNow.getMinutes(),dStopTime.getSeconds()-dNow.getSeconds());
  14. strContent = "&nbsp;<b>"+setLeadingZero(dNow.getHours())+":"+setLeadingZero(dNow.getMinutes())+":"+setLeadingZero(dNow.getSeconds())+"</b>&nbsp;";
  15. if(dNow.getMinutes()<1) strContent="<font color=#ff0000>"+strContent+"</font>";
  16. document.getElementById("vtimer").innerHTML=strContent;
  17. clockID = setTimeout("UpdateClock()", 500);
  18. } else {
  19. clearTimeout(clockID);
  20. clockID = 0;
  21. document.getElementById("vtimer").innerHTML = "<b>00:00:00</b>";
  22. }
  23. }
  24. function setLeadingZero(i) {
  25. return (i<10) ? "0"+i : i;
  26. }
  27. clockID = setTimeout("UpdateClock()", 500);
  28.  
  29.  
  30.  
  31. </script>
Code in tags please - moderator
Mar 8 '07 #1
2 1414
sumittyagi
202 Expert 100+
use setInterval and clearInterval if you want to repeatedly run a function after specified time. setTimeout runs ur function only once.
Mar 8 '07 #2
acoder
16,027 Expert Mod 8TB
Changed thread title.
Mar 8 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
2
by: Robert | last post by:
Hi there! I have a problem I can't get rid of... I hope anyone can help me with it! For a room-booking application I need to select available rooms for a given period. First I do the...
3
by: Fabian | last post by:
http://www.lajzar.co.uk/unit/ Is an index page. I have javascripts to open up submenus. But tehre are quiter a lot of them, all simialr. Is there a way to unify all that javascript into a single...
8
by: ilPostino | last post by:
This question is for long term coders hense the extra posting on c# ;) I find coding for long periods and on big projects frustrating when trying to use keyboard AND mouse. Do any of you use just...
1
by: anthony hanson | last post by:
I am trying to write a stored proc the calculates a moving average over three periods. In the following example, I need to stratify the data by personID and RecordID in the #Temp table, but I am...
8
by: Joseph | last post by:
I have a textBox that people writes stories in it. They can use for format. I have Aspell installed on the server, so people can make correction to their text. Sometimes, they forget to add a...
3
by: jdph40 | last post by:
In Access 2002, I designed a simple database for our Safety department to enter results of a survey. There are 41 true/false statements. I have a main form called frmSurvey with a subform called...
64
by: Bayazee | last post by:
hi can we hide a python code ? if i want to write a commercial software can i hide my source code from users access ? we can conver it to pyc but this file can decompiled ... so ...!! do you...
14
by: --CELKO-- | last post by:
Can I get a little help? Given a very simple table of events, with their durations, I want to consolidate time periods for an event that (1) touch each other or (2) overlap each other. CREATE...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.