Currently I have a display where I have a button START, on click of this button the timer starts and it gets replaced by 2 buttons. these 2 buttons are submit and walkaway. on the submit of each of these buttons a script is run. on the click of submit button, test.php is initiated.
Everything is working fine, but there are few changes that i am not able to make
First
I wish to combine the start and submit button, i.e
a) on the click of start button, timer should start,
b) the 2 new buttons should appear and
c) the script test.php should run.
it would be nice if i could just change the text of start button to submit and keep the button same and run the above 3 functionalities on click of start button, however different aspects are also welcomed
Second
when the time of the timer reaches 0:00 it should get reset to its initial stage and the buttons should also get changed to their original state i.e
a) the 2 buttons should disappear and get replaced by start button
b) clock should show its initial value i.e 2:00
Part of js code. entire code @fiddle
/*******Code for the three buttons*********/
$(document).ready(function (){
$("#startClock").click(function (){
$("#startClock").fadeOut(function(){
$("#walkaway").fadeIn().delay(120000).fadeOut();
$("#submitamt").fadeIn().delay(120000).fadeOut(function(){
$("#startClock").fadeIn();
});
})
});
});
/*******Code for running test.php script*********/
$(document).ready(function(){
$('#submitamt').click(function(){
var txtbox = $('#txt').val();
var hiddenTxt = $('#hidden').val();
$.ajax({
type:'post',
url:'test.php',
data:{txt:txtbox,hidden:hiddenTxt},
cache:false,
success: function(returndata){
$('#proddisplay').html(returndata);
console.log(returndata)
}
});
})
})
/*******Code for starting the clock*********/
$('#startClock').click(function () {
var counter = 120;
setInterval(function () {
counter--;
if (counter >= 0) {
span = document.getElementById("count");
span.innerHTML = '<span class="first_digit">' + parseInt(counter / 60) + '</span><span class="second_digit">:</span><span class="third_digit">' + parseInt((counter % 60) / 10) + '</span> <span class="fourth_digit">' + (counter % 60) % 10;
}
if (counter === 0) {
alert('sorry, out of time');
clearInterval(counter);
}
}, 1000);
});
Try this example (using different buttons rather than changing button's text):