PDA

View Full Version : adding a couple of factors to a peice of code


cat_evilness
11-23-2002, 10:46 PM
Hey guys, the code below works well but there's a couple more things i need it to do. Firstly I want it so that the user can't push the button when the counter is at 10. And secondly I want it so that when the counter reaches 0 the user can no longer push the button. If anyone could edit the peice of code below so that it could do this I would be very grateful.
Thankyou,
Cat :thumbsup:

<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>

ConfusedOfLife
11-23-2002, 11:16 PM
<html>
<head>
<script language="javascript">
<!--
var countdownValue='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 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>