I'm currently working on an online auction bidding project that involves users placing bids before time runs out. I found a solution on this link.
My goal is to run the timer loop continuously. When the timer hits 0, I want the bid button to be disabled and then enabled when the timer starts again. How can I achieve this? Below is the code I referenced from the provided link which only runs twice.
function timer(startFrom, delay, intervalDelay, runTimes, notFirstRun){
if(typeof runTimes == "undefined") runTimes = 1;
if(runTimes-- < 0) return;
setTimeout(function(){
var ctn = startFrom;
var timer1 = window.setInterval(function(){
document.getElementById('out1').innerHTML = ctn--;
document.getElementById('out2').innerHTML = "You can Place BID!";
if(ctn <= 0){
gotit();
clearInterval(timer1);
timer(startFrom, delay, intervalDelay, runTimes, true);
}
}, intervalDelay);
}, notFirstRun?delay*1000:0);
}
window.onload=function() {
timer(10, 5, 1000, 2);
}
function gotit()
{
document.getElementById('out2').innerHTML = "Bidding closed!";
}
<html>
<body>
<div>Biddind closes in <span id="out1"></span> seconds!</div>
<div id="out2">You can Place BID </div>
<form>
<input type="text" name="amount"/>
<input type="submit" id="btnct" value="Place Bid"/>
</form>
</body>
</html>