View Full Version : adding multiple countdown scripts to a page!
cat_evilness
08-13-2002, 05:36 PM
Hey guys, finally I got the code I wanted to do a count down on my page, thankyou!!!! But now I need to be able to add multiple countdowns onto the same page but all counting different times! Is it possible to do this? and if so what variable names will I have to change so that they don't clash with one another??
Here is the code:
<html>
<head>
<script language="javascript">
<!--
var countdownValue='10';
function countdownScript()
{
var showCountdown=document.getElementById('countdown');
showCountdown.innerHTML=countdownValue;
setTimeout("countdownScript();", 1000);
countdownValue--;
}
//-->
</script>
</head>
<body>
<span id="countdown"></span>
<script language="javascript">
<!--
countdownScript();
//-->
</script>
</body>
</html>
thankyou!!
Cat :p
whackaxe
08-13-2002, 06:07 PM
ypu can just add a number to the end of each variable
<html>
<head>
<script language="javascript">
<!--
var countdownValue01='10';
function countdownScript01()
{
var showCountdown01=document.getElementById('countdown01');
showCountdown01.innerHTML=countdownValue01;
setTimeout("countdownScript();", 1000);
countdownValue01--;
}
//-->
</script>
</head>
<body>
<span id="countdown01"></span>
<script language="javascript">
<!--
countdownScript01();
//-->
</script>
</body>
</html>
adn there you have it
requestcode
08-13-2002, 06:27 PM
Here is another way. I also added code to stop the timer when it reaches zero.
<html>
<head>
<script language="javascript">
<!--
var countdownValue='10';
var countdownValue2='10';
function countdownScript()
{
var showCountdown=document.getElementById('countdown');
showCountdown.innerHTML=countdownValue;
if(countdownValue<=0)
{clearTimeout(Timer)}
else
{Timer=setTimeout("countdownScript();", 1000);}
countdownValue--;
}
function countdownScript2()
{
var showCountdown2=document.getElementById('countdown2');
showCountdown2.innerHTML=countdownValue2;
if(countdownValue2<=0)
{clearTimeout(Timer2)}
else
{Timer2=setTimeout("countdownScript2();", 1000);}
countdownValue2--;
}
//-->
</script>
</head>
<body>
<span id="countdown" style="position:absolute;top:10;left:20"></span>
<span id="countdown2" style="position:absolute;top:30;left:20"></span>
<script language="javascript">
<!--
countdownScript();
countdownScript2();
//-->
</script>
</body>
</html>
Skyzyx
08-14-2002, 02:30 AM
Hey guys, finally I got the code I wanted to do a count down on my page, thankyou!!!!
You're welcome Cat! =)
cat_evilness
08-14-2002, 03:05 AM
okay guys, now I finally have my counters i need to figure out how to make a variable that holds the total of all the counters. for example if all the counters are at 10 then the total will be 50, if they are all at 1 then it will be 5 and blah blah blah!!
If anyone could help me I'd be very very gratefull!!
When this bloody virtual pet is finished and I hopefully have my A then I will put it up for you guys to play with.. oh and anyone who wants can be part of the testing team!?!
Cat x:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.