Online Timer

Set it and forget it. This script calculates the target end time based on user input and updates the display every second until the deadline is reached.

00:00:00
Set time and click Start

Copy the Script

<script>
var timerInterval;

function startCountdown() {
    // Get inputs (simplified)
    var m = parseInt(document.getElementById("min").value) || 0;
    var s = parseInt(document.getElementById("sec").value) || 0;
    
    // Calculate total seconds
    var totalTime = (m * 60) + s;
    var display = document.getElementById("display");

    clearInterval(timerInterval); // Clear existing

    timerInterval = setInterval(function() {
        if (totalTime <= 0) {
            clearInterval(timerInterval);
            display.innerHTML = "Time's Up!";
            alert("Timer Finished!");
        } else {
            totalTime--;
            var mins = Math.floor(totalTime / 60);
            var secs = totalTime % 60;
            // Pad with leading zero
            display.innerHTML = (mins < 10 ? "0" : "") + mins + ":" + (secs < 10 ? "0" : "") + secs;
        }
    }, 1000);
}
</script>

<input id="min" placeholder="Min"> <input id="sec" placeholder="Sec">
<button onclick="startCountdown()">Start</button>
<div id="display">00:00</div>

Frequently Asked Questions

Yes, `setInterval` continues running even if you switch tabs, though modern browsers may reduce the update frequency (throttling) to save battery. The end time will still be accurate.

Yes. You can add `new Audio('beep.mp3').play()` inside the `if (distance < 0)` block to trigger an audio alarm.

Simply use `clearInterval(timerId)` to stop the loop and reset the display text back to '00:00:00'.