View Full Version : Mutiple Countdowns

09-27-2003, 09:41 PM
Hi, I'm sorry you guys but I have no idea what I'm doing. I'm using this script below. It countsdown to dates. What I want is to have more then one of theses on a webpage at the same time (counting down to differnet days). I don't know what I have to edit to get more then one to work. I read the thing on how to edit it for mutiples. But I can't figure it out. I also tried some things of my own. I really need some help please. Any Ideas? I have no idea what i'm doing. Help? Here's the script:

<script language="JavaScript1.2">

Dynamic countdown Script- Dynamic Drive (www.dynamicdrive.com)
For full source code, 100's more DHTML scripts, and TOS,
visit http://www.dynamicdrive.com

function setcountdown(theyear,themonth,theday){

//////////CONFIGURE THE COUNTDOWN SCRIPT HERE//////////////////

//STEP 1: Configure the countdown-to date, in the format year, month, day:

//STEP 2: Change the two text below to reflect the occasion, and message to display on that occasion, respectively
var occasion="Thanksgiving."
var message_on_occasion="Happy Thanksgiving"

//STEP 3: Configure the below 5 variables to set the width, height, background color, and text style of the countdown area
var countdownwidth='480px'
var countdownheight='20px'
var countdownbgcolor='lightblue'
var opentags='<font face="Verdana"><small>'
var closetags='</small></font>'

//////////DO NOT EDIT PASS THIS LINE//////////////////

var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var crosscount=''

function start_countdown(){
if (document.layers)
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countdownie") : countdownie

if (document.all||document.getElementById)
document.write('<span id="countdownie" style="width:'+countdownwidth+'; background-color:'+countdownbgcolor+'"></span>')


function countdown(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[mo-1]+" "+da+", "+yr
//if on day of occasion
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+message_on_occasion+closeta gs)
else if (document.all||document.getElementById)
//if passed day of occasion
else if (dday<=-1){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+"Occasion already passed! "+closetags)
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+"Occasion already passed! "+closetags
//else, if not yet
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left until "+occasion+closetags)
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds left until "+occasion+closetags

<ilayer id="countdownnsmain" width=&{countdownwidth}; height=&{countdownheight}; bgColor=&{countdownbgcolor}; visibility=hide><layer id="countdownnssub" width=&{countdownwidth}; height=&{countdownheight}; left=0 top=0></layer></ilayer>

So what would I need to edit to get mutiple scripts working on the same page? Thanks for the help.
- Danny

Willy Duitt
09-29-2003, 06:38 AM
Firstly; This probably should have been posted in the Dynamic Drive Forum. :)

Secondly; I tried to paste your code into a tester but it threw more errors than I cared to try to fix. (most likely from multiple cc&p) :(

Lastly; I found this nice short script written by: Stevie Peele
in the Post a Javascript Forum that should not be difficult to
place multiple times on a page. ;)

<script type="text/javascript">
var now = new Date();
var then = new Date("December 25,2003");
var gap = then.getTime() - now.getTime();
gap = Math.floor(gap / (1000 * 60 * 60 * 24));
document.write("Only " + gap + " more days until Christmas");