cat_evilness
11-22-2002, 06:29 PM
You guys did a great job with the adding 1 to a variable now I need help with something a little bit harder.
The variables I want to add 1 to are made up from counters that count down from 10 to 1. Is there anyway you can make it so that if you push a button it will add 1 to the variable, thus the counter will be going back by 1. There are a couple of other things. I need it so that the counter wont exceed 10 and when it reaches 0 you wont be able to add 1 anymore.
Here is the code I already have:
<html>
<head>
<script language="javascript">
<!--
var countdownValue='10';
var countdownValue2='10';
var countdownValue3='10';
var countdownValue4='10';
var countdownValue5='10';
function countdownScript()
{
var showCountdown=document.getElementById('countdown');
showCountdown.innerHTML=countdownValue;
if(countdownValue<=0)
{clearTimeout(Timer)}
else
{Timer=setTimeout("countdownScript();", 100000);}
countdownValue--;
}
function countdownScript2()
{
var showCountdown2=document.getElementById('countdown2');
showCountdown2.innerHTML=countdownValue2;
if(countdownValue2<=0)
{clearTimeout(Timer2)}
else
{Timer2=setTimeout("countdownScript2();", 110000);}
countdownValue2--;
}
function countdownScript3()
{
var showCountdown3=document.getElementById('countdown3');
showCountdown3.innerHTML=countdownValue3;
if(countdownValue3<=0)
{clearTimeout(Timer3)}
else
{Timer3=setTimeout("countdownScript3();", 200000);}
countdownValue3--;
}
function countdownScript4()
{
var showCountdown4=document.getElementById('countdown4');
showCountdown4.innerHTML=countdownValue4;
if(countdownValue4<=0)
{clearTimeout(Timer4)}
else
{Timer4=setTimeout("countdownScript4();", 200000);}
countdownValue4--;
}
function countdownScript5()
{
var showCountdown5=document.getElementById('countdown5');
showCountdown5.innerHTML=countdownValue5;
if(countdownValue5<=0)
{clearTimeout(Timer5)}
else
{Timer5=setTimeout("countdownScript5();", 90000);}
countdownValue5--;
}
//-->
</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>
Hunger:</br>
Health:</br>
Fitness:</br>
Energy:</br>
</td>
<td width="40" bgcolor="#000000" 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>
<script language="javascript">
<!--
countdownScript();
countdownScript2();
countdownScript3();
countdownScript4();
countdownScript5();
//-->
</script>
</td>
</tr>
</table>
</form>
</body>
</html>
If anyone could help me out by adding the code with buttons etc. I would be very grateful.
Thankyou
Cat :thumbsup:
The variables I want to add 1 to are made up from counters that count down from 10 to 1. Is there anyway you can make it so that if you push a button it will add 1 to the variable, thus the counter will be going back by 1. There are a couple of other things. I need it so that the counter wont exceed 10 and when it reaches 0 you wont be able to add 1 anymore.
Here is the code I already have:
<html>
<head>
<script language="javascript">
<!--
var countdownValue='10';
var countdownValue2='10';
var countdownValue3='10';
var countdownValue4='10';
var countdownValue5='10';
function countdownScript()
{
var showCountdown=document.getElementById('countdown');
showCountdown.innerHTML=countdownValue;
if(countdownValue<=0)
{clearTimeout(Timer)}
else
{Timer=setTimeout("countdownScript();", 100000);}
countdownValue--;
}
function countdownScript2()
{
var showCountdown2=document.getElementById('countdown2');
showCountdown2.innerHTML=countdownValue2;
if(countdownValue2<=0)
{clearTimeout(Timer2)}
else
{Timer2=setTimeout("countdownScript2();", 110000);}
countdownValue2--;
}
function countdownScript3()
{
var showCountdown3=document.getElementById('countdown3');
showCountdown3.innerHTML=countdownValue3;
if(countdownValue3<=0)
{clearTimeout(Timer3)}
else
{Timer3=setTimeout("countdownScript3();", 200000);}
countdownValue3--;
}
function countdownScript4()
{
var showCountdown4=document.getElementById('countdown4');
showCountdown4.innerHTML=countdownValue4;
if(countdownValue4<=0)
{clearTimeout(Timer4)}
else
{Timer4=setTimeout("countdownScript4();", 200000);}
countdownValue4--;
}
function countdownScript5()
{
var showCountdown5=document.getElementById('countdown5');
showCountdown5.innerHTML=countdownValue5;
if(countdownValue5<=0)
{clearTimeout(Timer5)}
else
{Timer5=setTimeout("countdownScript5();", 90000);}
countdownValue5--;
}
//-->
</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>
Hunger:</br>
Health:</br>
Fitness:</br>
Energy:</br>
</td>
<td width="40" bgcolor="#000000" 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>
<script language="javascript">
<!--
countdownScript();
countdownScript2();
countdownScript3();
countdownScript4();
countdownScript5();
//-->
</script>
</td>
</tr>
</table>
</form>
</body>
</html>
If anyone could help me out by adding the code with buttons etc. I would be very grateful.
Thankyou
Cat :thumbsup: