I'm working on a simple countdown timer using Javascript/jQuery.
Basically, I can enter the amount of minutes in the input field and it will convert it to minutes and seconds and starts the countdown.
so, if i enter 30, it will start the countdown from 29 in this format: 29:59
What I need to do is to be able to enter the minutes and seconds in the input field and it should countdown properly but I have no idea how to do this.
for example, I want to enter 26:15
and the countdown should start from that time.
this is my entire code:
HTML:
<h1>Enter minutes you want to work </h1><p>0:00</p>
<input id="request" type="text" value="<?php echo $end_time; ?>">
<input id="time" type="text" value="">
<a href="#" class="click">Click here</a>
jQuery:
<script>
$('.click').click(function () {
var rawAmount = $('#request').val();
var cleanAmount = parseInt(rawAmount);
var totalAmount = cleanAmount * 60;
$('#request').val(" ");
var loop, theFunction = function () {
totalAmount--;
if (totalAmount == 0) {
clearInterval(loop);
}
var minutes = parseInt(totalAmount/60);
var seconds = parseInt(totalAmount%60);
if(seconds < 10)
seconds = "0"+seconds;
$('p').text(minutes + ":" + seconds);
$('#time').val(minutes + ":" + seconds);
};
var loop = setInterval(theFunction, 1000);
})
</script>
could someone please advise on this issue?