I am working on Question / Answer game and i need to set a countdown for each question. If time is out, call next button click.
Here is my code, demo:
https://jsfiddle.net/0ex9neh3/1/
How can I reset a timer on trigger click?
Here is a html part:
<div id="my-timer">
Page Will Redirect with in <b id="show-time">10</b> seconds
</div>
<input type="button" name="next" value="Next question" class="wpProQuiz_button wpProQuiz_QuestionButton next-button" style="float: right;">
Here is JS:
$(document).ready(function() {
var settimmer = 0;
$(function() {
window.setInterval(function() {
var timeCounter = $("b[id=show-time]").html();
var updateTime = eval(timeCounter) - eval(1);
$("b[id=show-time]").html(updateTime);
if (updateTime == 0) {
$("input[value='Next question']").trigger(
'click');
}
}, 1000);
});
$("input[value='Next question']").click(function() {
alert('timeout reset')
});
});