How to mark time in the database of a javascript timer

Asked

Viewed 296 times

0

I have javascript code that calculates the time (seconds, minutes, hours) I have an input of type Submit to each click wanted to register in the database the time, and that automatically came back and continued timing to return I will use the refresh, but to continue timing and mark the time?.

function formatatempo(segs) {
min = 0;
hr = 0;
/*
if hr < 10 then hr = "0"&hr
if min < 10 then min = "0"&min
if segs < 10 then segs = "0"&segs
*/
while(segs>=60) {
if (segs >=60) {
segs = segs-60;
min = min+1;
}
}

while(min>=60) {
if (min >=60) {
min = min-60;
hr = hr+1;
}
}

if (hr < 10) {hr = "0"+hr}
if (min < 10) {min = "0"+min}
if (segs < 10) {segs = "0"+segs}
fin = hr+":"+min+":"+segs
return fin;
}
var segundos = 0; //inicio do cronometro
function conta() {
segundos++;
document.getElementById("counter").innerHTML = formatatempo(segundos);
}

function inicia(){
interval = setInterval("conta();",1000);
}

function para(){
clearInterval(interval);
}

function zera(){
clearInterval(interval);
segundos = 0;
document.getElementById("counter").innerHTML = formatatempo(segundos);
}


</script>
</font>


  </div> 






  <div class="button">
  <form type="text" action="bd_resultado.php"  method="post">

  <input type="button" value="Parar" onclick="para();"> <input type="button" value="Iniciar" onclick="inicia();"> <input type="button" value="Finalizar" onclick="zera();">

<input type="hidden" name="tempo" value="<script>document.write(counter)
  • Make an INSERT and then a SELECT.

  • look for lib Moment.js. It will help a lot.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.