PDA

View Full Version : adapting a counter script, please help


cat_evilness
11-24-2002, 12:54 PM
Hey guys,

Does anyone know how I could adapt the code below so that I can have more than 1 count down?
It's probably really easy but everything I have tried comes up with errors.

<html>
<head>
<script language="javascript">
<!--
var countdownValue='10';

function countdownScript(){
if(countdownValue>=10){
countdownValue=10
}
countdown.innerHTML=countdownValue;
if(countdownValue<=0){
clearTimeout(Timer)
}
else{
countdownValue--;
Timer=setTimeout("countdownScript();", 3000);
}
}

function hmm(){
clearTimeout(Timer)
countdownValue+=2
countdownScript()
}

onload=countdownScript
//-->
</script>
<title>Virtual Pet - Version 1.0</title>
</head>
<body bgcolor="#FF9900" text="#ffff99" link="#00ff00" alink="#ffa500" vlink="#ff0000">
<basefont size="3">
<table width="220" valign="top" border="0">
<tr>
<td width="180" bgcolor="#000000" valign="left" align="left" border="0">
Mood:</br>
</td>
<td width="40" bgcolor="#000000" valign="left" align="left" border="0">
<span id="countdown"></span></br>
</td>
</tr>
</table>

<form name=f1>
<input type="button" value="Button" onclick="hmm()">
</form>
</body>
</html>

Thankyou,
Cat

scroots
11-24-2002, 02:18 PM
just change all intances of things so hmm() would be come hmm2() etc.

so your code for a second script would be

<html>
<head>
<script language="javascript">
<!--
var countdownValue2='10';

function countdownScript2(){
if(countdownValue2>=10){
countdownValue2=10
}
countdown2.innerHTML=countdownValue2;
if(countdownValue2<=0){
clearTimeout(Timer)
}
else{
countdownValue2--;
Timer=setTimeout("countdownScript2();", 3000);
}
}

function hmm2(){
clearTimeout(Timer)
countdownValue2+=2
countdownScript2()
}

onload=countdownScript2
//-->
</script>
<title>Virtual Pet - Version 1.0</title>
</head>
<body bgcolor="#FF9900" text="#ffff99" link="#00ff00" alink="#ffa500" vlink="#ff0000">
<basefont size="3">
<table width="220" valign="top" border="0">
<tr>
<td width="180" bgcolor="#000000" valign="left" align="left" border="0">
Mood:</br>
</td>
<td width="40" bgcolor="#000000" valign="left" align="left" border="0">
<span id="countdown2"></span></br>
</td>
</tr>
</table>

<form name=f1>
<input type="button" value="Button" onclick="hmm2()">
</form>
</body>
</html>


scroots