PDA

View Full Version : problem in code, involving counters


cat_evilness
11-24-2002, 03:38 PM
In the code below, 5 counters are suppose to be displayed. The buttons on the right are used to add 1 to the counters. The problem is that when the page loads only 1 counter is displayed and the other ones only show up when their button is pressed and then some of the counters don't work.

If anyone knows what to do to the code I would be very grateful.
Cat :D

<script language="javascript">
<!--
function open () {return true;}
//-->
</script>
<html>
<head>
<script language="javascript">
<!--
var countdownValue='10';
var countdownValue2='10';
var countdownValue3='10';
var countdownValue4='10';
var countdownValue5='10';

function countdownScript(){
if(countdownValue>=10){
countdownValue=10
}

if ( countdownValue == 10 || countdownValue == 0 )
document.forms[0].elements[0].disabled = true;
else
document.forms[0].elements[0].disabled = false;

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

function countdownScript2(){
if(countdownValue2>=10){
countdownValue2=10
}

if ( countdownValue2 == 10 || countdownValue2 == 0 )
document.forms[0].elements[0].disabled = true;
else
document.forms[0].elements[0].disabled = false;

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

function countdownScript3(){
if(countdownValue3>=10){
countdownValue3=10
}

countdown3.innerHTML=countdownValue3;
if(countdownValue3<=0){
clearTimeout(Timer)
}
else{
countdownValue3--;
Timer=setTimeout("countdownScript3();", 3000);
}
}

function countdownScript4(){
if(countdownValue4>=10){
countdownValue4=10
}

countdown4.innerHTML=countdownValue4;
if(countdownValue4<=0){
clearTimeout(Timer)
}
else{
countdownValue4--;
Timer=setTimeout("countdownScript4();", 3000);
}
}

function countdownScript5(){
if(countdownValue5>=10){
countdownValue5=10
}

countdown5.innerHTML=countdownValue5;
if(countdownValue5<=0){
clearTimeout(Timer)
}
else{
countdownValue5--;
Timer=setTimeout("countdownScript5();", 3000);
}
}

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


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

function hmm3(){
clearTimeout(Timer)
countdownValue3+=2
countdownScript3()
}

function hmm4(){
clearTimeout(Timer)
countdownValue4+=2
countdownScript4()
}

function hmm5(){
clearTimeout(Timer)
countdownValue5+=2
countdownScript5()
}

onload=countdownScript
onload=countdownScript2
onload=countdownScript3
//-->
</script>
<title>Virtual Pet - Version 1.0</title>
</head>
<body bgcolor="#0099FF" text="#ffff99" link="#00ff00" alink="#ffa500" vlink="#ff0000">
<basefont size="3">
<table width="500" valign="top" border="0">
<tr>
<td width="190" valign="left" align="left" border="0">
<table width="190" valign="top" border="1">
<td width="190" height="100" bgcolor="#FF9900" valign="left" align="left" border="1">
Hunger:</br>
Mood:</br>
Health:</br>
Fitness:</br>
Energy:</br>
</td>
<td width="40" bgcolor="#FF9900" valign="left" align="left" border="0">
<span id="countdown"></span></br>
<span id="countdown2"></span></br>
<span id="countdown3"></span></br>
<span id="countdown4"></span></br>
<span id="countdown5"></span></br>
</td>
</table>
</td>
<td width="180" valign="left" align="left" border="0">
<div align="center"><img src="smalllogo.gif"></div>
</td>
<td width="200" valign="left" align="left" border="0">
<table width="200" valign="top" border="1">
<td width="200" height="100" bgcolor="#FF9900" valign="left" align="left" border="1">

<form name=f1>
<input type="button" value="Feed" onclick="hmm()"></br>
<input type="button" value="Play" onclick="hmm2()"></br>
<input type="button" value="Medicine" onclick="hmm3()"></br>
<input type="button" value="Exercise" onclick="hmm4()"></br>
<input type="button" value="Bed" onclick="hmm5()"></br>
</form>
</td>
</table>
</td>
</tr>
</table>
</body>
</html>

scroots
11-24-2002, 04:15 PM
chnage your code, so that the body tag is:

<body onload="countdownScript();countdownScript2();countdownScript3();countdownScript4();countdownScript5();" bgcolor="#0099FF" text="#ffff99" link="#00ff00" alink="#ffa500" vlink="#ff0000">


and delete the following from your script

onload=countdownScript
onload=countdownScript2
onload=countdownScript3

scroots