Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I click the reset button it clears everything except the countdown timer adds a second countdown when I click the reset button I would like it not to do that! I would like it to clear the first countdown and just use the new one!
XML
<?php
// name your app
$app_title = "100 Seconds";
// theme color of your app (can be a hex)
$app_color = "#FF00CA";
// text color of your app (goes over theme color)
$app_tcolor = "#FFFFFF";
?>
<!DOCTYPE html>
<html>
<head>
<?php echo "<title>$app_title - Misdew</title>"; ?>
<meta charset="UTF-8">
<meta content="We're a social network. Check us out." name="description">
<meta content="Misdew, MD, Social, Network, Communication" name="keywords">
<link rel="icon" type="image/png" href="/img/MD_logo.png">
<link rel="apple-touch-icon" href="/img/MD_logo.png">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#a64ca6">
<link rel="apple-touch-icon" href="/MD_logo2.png">
<link rel="stylesheet" type="text/css" href="/styles_1.css">
</head>
<body>
<center>
<table class="app_top_bar"><tr><td style="width: 15%; background-color: #a64ca6;" onclick="window.location='/panel';">M</td><td class="app_top" style="<?php echo "background-color: $app_color;"; ?>">
<?php echo "<span style=\"color: $app_tcolor;\">$app_title</span>"; ?>
</td></tr></table>
<br><br><br><br>
<div id="ins">Instructions: You have 100 seconds to tap the +1 button as many times as you can!</div>
<br>
<div id="PlayArea">0</div>
<center><div id="pldiv"><button id="Plus" onclick="PlusOne();StartTimer();" style="background-color:#FF00CA;border:none;outline:none;width:120px;height:60px;display:block;border:none;outline:none;">+1</button></div><button id="reset" onclick="reset()" style="background-color:#CA00FF;border:none;outline:none;width:120px;height:60px;display:block;border:none;outline:none;">reset</button></center>
<script>
n=100;
document.window=0;
z=0;
function PlusOne(){document.window=document.window+1;
x=document.getElementById("PlayArea");
x.innerHTML = document.window;
}function StartTimer(){if(z==0){tim = setTimeout(function(){ StopCounter(); },n*1000);z=1;}
else{;}}
function StopCounter(){if(document.window==1){document.window="You got "+ document.window +" point!";}
else{document.window = "You got "+ document.window +" points!";}
document.getElementById('pldiv').innerHTML = '<button id="Plus" disabled onclick="PlusOne();StartTimer();" style="background-color:#FF00CA;border:none;outline:none;width:120px;height:60px;display:block;border:none;outline:none;">+1</button>';
x.innerHTML = document.window;
}function reset(){clearTimeout(tim);
z=0;
document.window=0;
x.innerHTML = document.window;
document.getElementById('pldiv').innerHTML = '<button id="Plus" onclick="PlusOne();StartTimer();" style="background-color:#FF00CA;border:none;outline:none;width:120px;height:60px;display:block;border:none;outline:none;">+1</button>';
}function startTimer(duration, display) {
var timer = duration, minutes, seconds;
    setInterval(function () {
        minutes = parseInt(timer / 60, 10);
        seconds = parseInt(timer % 60, 10);

        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;

        display.textContent = minutes + ":" + seconds;

        if (--timer < 0) {
            timer = duration;
        }
    }, 1000);
}

window.onload = function () {
    var fiveMinutes = 60 * 5,
        display = document.querySelector('#time');
    startTimer(fiveMinutes, display);
};
</script>

<br><br>
</center>
</body>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900