473,322 Members | 1,510 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,322 software developers and data experts.

A cool count down timer sourcecode !

Copy the code below and save in a .htm file, for example : 1.htm, then
run it in browser, you'll see a cool count down timer ! If it doesn't
work, you may open http://www.fillweb.com in IE and View->Source, and
the latest version of count down timer will show you !

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>Welcome to Fillweb home page</title>
<meta name="keywords" content="fillweb, form filler, fill forms
automatically, account logon login, single sign on, fill web forms,
fill online forms automatically, form filling software, ai web
automatic auto fill out forms fill in forms">
<script language="JavaScript">
<!--
var timerID;
var timerRunning = false;
var today = new Date();
var startday = new Date();
var secPerDay = 0;
var minPerDay = 0;
var hourPerDay = 0;
var secsLeft = 0;
var secsRound = 0;
var secsRemain = 0;
var minLeft = 0;
var minRound = 0;
var minRemain = 0;
var timeRemain = 0;
/* This function will stop the clock */
function stopclock()
{
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
/* This function will start the clock */
function startclock()
{
stopclock();
countdown();
}
function startclock_cn()
{
stopclock();
showtime_cn();
}
/* This function will display the count-up */
function countdown()
{
startday = new Date("November 01, 2006 00:00 GMT");
startday.setYear("2006");
today = new Date();
secsPerDay = 1000 ;
minPerDay = 60 * 1000 ;
hoursPerDay = 60 * 60 * 1000;
PerDay = 24 * 60 * 60 * 1000;
/* Seconds */
secsLeft = (startday.getTime() - today.getTime()) / minPerDay;
secsRound = Math.round(secsLeft);
secsRemain = secsLeft - secsRound;
secsRemain = (secsRemain < 0) ? secsRemain = 60 - ((secsRound -
secsLeft) * 60) : secsRemain = (secsLeft - secsRound) * 60;
secsRemain = Math.round(secsRemain);
/* Minutes */
minLeft = ((startday.getTime() - today.getTime()) /
hoursPerDay);
minRound = Math.round(minLeft);
minRemain = minLeft - minRound;
minRemain = (minRemain < 0) ? minRemain = 60 - ((minRound -
minLeft) * 60) : minRemain = ((minLeft - minRound) * 60);
minRemain = Math.round(minRemain - 0.495);
/* Hours */
hoursLeft = ((startday.getTime() - today.getTime()) / PerDay);
hoursRound = Math.round(hoursLeft);
hoursRemain = hoursLeft - hoursRound;
hoursRemain = (hoursRemain < 0) ? hoursRemain = 24 -
((hoursRound - hoursLeft) * 24) : hoursRemain = ((hoursLeft -
hoursRound) * 24);
hoursRemain = Math.round(hoursRemain - 0.5);
/* Days */
daysLeft = ((startday.getTime() - today.getTime()) / PerDay);
daysLeft = (daysLeft - 0.5);
daysRound = Math.round(daysLeft);
daysRemain = daysRound;
/* Time */
if (daysRemain == 1)
{
day_rem = " day, "
}
else
{
day_rem = " days, "
}
if (hoursRemain == 1)
{
hour_rem = " hour, "
}
else
{
hour_rem = " hours, "
}
if (minRemain == 1)
{
min_rem = " minute, "
}
else
{
min_rem = " minutes, "
}
if (secsRemain == 1 || secsRemain == 0)
{
sec_rem = " second"
}
else
{
sec_rem = " seconds"
}
timeRemain = "Fillweb is coming in " + daysRemain + day_rem +
hoursRemain + hour_rem + minRemain +
min_rem + secsRemain + sec_rem;
document.counter.face.value = timeRemain;
timerID = setTimeout("countdown()",1000);
timerRunning = true;
}
//-->
</script>
</head>
<body onLoad="startclock()" bgcolor="#000000">
<div align="center">
<table border="0" width="700" height="333" cellspacing="2">
<tr>
<td background="images/milkyway.jpg"></td>
</tr>
<tr>
<td align="center" height="18" valign="bottom">
<form name="counter" style="position: relative">
<input type="text" name="face" size="100" value="A browser
supporting JavaScript 1.1+ is needed." style="border:1px solid
#000000; background-color:#000000; font-size:9pt; color:#FFFFFF;
text-align:center; position:relative; ">
</form>
</td>
</tr>
</table>
</div>
<script src="http://www.google-analytics.com/urchin.js"
type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-859503-1";
urchinTracker();
</script>
</body>
</html>

Oct 30 '06 #1
2 3569
He********@gmail.com said the following on 10/29/2006 11:33 PM:
Copy the code below and save in a .htm file, for example : 1.htm, then
run it in browser, you'll see a cool count down timer ! If it doesn't
work, you may open http://www.fillweb.com in IE and View->Source, and
the latest version of count down timer will show you !
Looks like an overly bloated count down timer. You may want to look into
padding your numbers though, when it goes from a single digit to double
digits (or vice versa) everything jumps because of the difference in
string length.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Oct 30 '06 #2

He********@gmail.com wrote:
Copy the code below and save in a .htm file, for example : 1.htm, then
run it in browser, you'll see a cool count down timer !
Cool? It's verbose and pollutes the global space unnecessarily with 18
global variables where 1 will suffice. You'll find stuff on
calculating date differences here:

<URL: http://www.merlyn.demon.co.uk/js-date1.htm#diff >

Here's another version that doesn't make any allowance for summer time,
but maybe it's not needed:
<title>Simple Countdown</title>
<script type="text/javascript">

var diffClock = (function()
{
// Private variables
var startDate;
var clockEl;
var timerRef;

// Private methods
function addS(n){
return (n==1)? '':'s';
}

function addZ(n){
return (n < 10)? '0'+n : ''+n;
}

function diffDays(d1, d2){
var days = d2-d1; // Difference in milliseconds

if (days < 0){
return null;
}
var ms = days % 1000; // remainder ms
days = (days - ms) / 1000;
var secs = days % 60; // remainder seconds
days = (days - secs) / 60;
var mins = days % 60; // remainder minutes
days = (days - mins) / 60;
var hrs = days % 24; // remainder hours
days = (days - hrs) / 24; // days is now whole days
return [days, hrs, mins, secs, ms];
}

// Public methods
return {
// Start clock
start : function(el, d)
{
this.stop();
if (typeof el != 'object') return;
clockEl = el;
startDate = d;
this.run();
},

// Run the clock
run : function(){
var diff = diffDays(new Date(), startDate);
if (diff != null){
clockEl.innerHTML = 'Diff: '
+ diff[0] + ' day' + addS(diff[0]) + ', '
+ diff[1] + ' hour' + addS(diff[1]) + ', '
+ diff[2] + ' minute' + addS(diff[2]) + ' and '
+ addZ(diff[3]) + ' second' + addS(diff[3]) + '.';

// Schedule next update just after next full second
var runIn = 1050 - (new Date().getTime() % 1000);
timerRef = setTimeout('diffClock.run();', runIn);
} else {
this.stop();
}
},

// Stop the clock
stop : function(){
if (timerRef && clearTimeout){
clearTimeout(timerRef);
timerRef = null;
}
}
}
})();

window.onload = function(){
diffClock.start(document.getElementById('clock'),
new Date('2006/11/29 17:05:13'));
}

</script>
<div>Days until 2006/11/29 17:05:13
<div id="clock"></div>

<button id="button" onclick="diffClock.stop();">Stop</button>
--
Rob

Oct 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Noozer | last post by:
I have a timer on a form. It isn't firing at all. I know that the timer is enabled, and that the interval is low (4000, which should be 4 seconds). To ensure the timer wasn't being inadvertantly...
1
by: HeroinNO.4 | last post by:
Hello guys, sorry for my last version has a little "feature"(MS always call his bug "feature"), and now I fixed it and show the source to you all ! Just as the last version, copy the code below and...
2
by: HeroinNO.4 | last post by:
Hello guys, now the source code updated to November 06, 2006 00:00 GMT,and now I fixed it and show the source to you all ! Just as the last version, copy the code below and save in a .htm file, fox...
1
by: HeroinNO.4 | last post by:
You can open http://www.fillweb.com in IE and View->Source to see the latest version full featured count down timer source code, or you may also copy the code below and save in a "*.htm" file, for...
7
by: HeroinNO.4 | last post by:
Hello guys, free count down timer source code has updated to 06/11/27, you can copy the code below and save in a ".htm" file and run it in a browser support javascript 1.1 or later, or you can open...
2
by: Amit Dedhia | last post by:
Hi I am developing a scientific application which has moderate level image processing involved. In my application, there is a main application form which invokes another form. When this form...
7
by: =?Utf-8?B?YWxiZXJ0b3Nvcmlh?= | last post by:
Hi everybody, I'm using a system.timers.timer object like this: Dim aTimer As New System.Timers.Timer() In my page_load event I use this: aTimer.Interval = 5000 aTimer.Enabled = True...
3
missshaikh
by: missshaikh | last post by:
Hi all, i need the count down timer when button click the timer start and count down work on ASP.net :( i have one timer which is on JavaScript that run page onload . but i need the Button...
22
by: canabatz | last post by:
Hi all! i got a countdown timer for auctions that runing. i got a DIV that refreshs every 4 seconds that DIV is refreshed by ajax ,the file that is refreshed is timer.php for example!! my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.