[ PHP | JavaScript ]
Code Name: Simple Countdown Timer Added: 07/10/06
By: Ross
This code will count down the days/hours/minutes to a certain event. All you need to do is enter the date to count to (in the form hh, dd, mm, yyyy) and the text to display depending on if the event h
<div id="countBox" align="center"></div>

<script type="text/javascript">
<!--

// Enter the date and time to count down to in the form of hh,dd,mm,yyyy
var countTo = [09,25,12,2005];

// Text to appear before the event takes place. Use #d to represent the number of days, #h for hours, #m for minutes and #s for seconds
var beforeEvent = '#d Days, #h Hours, #m Minutes, #s Seconds until Christmas';

// Text to appear on the day of the event
var onEvent = 'Merry Christmas!';

// Text to appear after the event has finished
var afterEvent = 'Hope you all had a good Christmas';

var targetDate = new Date();
targetDate.setDate(countTo[1])
targetDate.setMonth(countTo[2]-1)
targetDate.setYear(countTo[3])

function setTime() {
   var todayDate = new Date();
   var dif = targetDate - todayDate;
   var totalDay = Math.floor(dif/86400000)
   var totalMinute = 60 - todayDate.getMinutes();
   var totalSeconds = 60 - todayDate.getSeconds();
   var totalHour = countTo[0] - todayDate.getHours();
   if(totalHour <0)
      totalHour = todayDate.getHours() - countTo[0];
   target = document.getElementById('countBox');
   if(totalDay == 0) {
      target.innerHTML = onEvent;
   } else if(total > 0) {
      target.innerHTML = beforeEvent.replace(/#d/gi,totalDay).replace(/#m/gi,totalMinute).replace(/#h/gi,totalHour).replace(/#s/gi,totalSeconds);
      setTimeout('setTime()', 1000);
   } else {
      target.innerHTML = afterEvent;
   }
}
setTime();
//-->
</script>



Stationary Printers
in West Molesey



Free Hosted
Bulletin Boards
Valid XHTML 1.1