// Get totalAmount from localStorage and if there is positive value call timeSet() immediately
var totalAmount = localStorage.getItem('countDown') || 0,
timeloop;
if (totalAmount) {
timeSet()
}
function timeSet () {
totalAmount--;
// Refresh value in localStorage
localStorage.setItem('countDown', totalAmount);
// If countdown is over, then remove value from storage and clear timeout
if (totalAmount < 0 ) {
localStorage.removeItem('countDown');
totalAmount = 0;
clearTimeout(timeloop);
return;
}
var minutes = parseInt(totalAmount/60);
var seconds = parseInt(totalAmount%60);
if(seconds < 10)
seconds = "0"+seconds;
$('#request').val(minutes + ":" + seconds);
timeloop = setTimeout(timeSet, 1000);
}
$('.enterTime').click(function () {
var reqVal = $('#request').val();
var parAmt = parseInt(reqVal);
if (timeloop) {
clearTimeout(timeloop)
}
totalAmount = parAmt * 60;
$('#request').val(" ");
timeSet();
})
// Clear timeout and remove localStorage value when resetting form
$('#countdown').on('reset', function () {
totalAmount = 0;
clearTimeout(timeloop);
localStorage.removeItem('countDown');
})
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.