How can I create a form that has a counter and stores the information in bank

0

I would like some help. I am trying to create a page that calculates the time that the person spends on some tasks that will be available on a form, hence the person selects the task and clicks on start where he begins to calculate the time spent through a stopwatch, being able to pause and stop and that this information is stored in a database so I can get it later.

    
asked by anonymous 16.03.2016 / 18:41

1 answer

0

Good afternoon, I put together a script that counts time, pause, resume and stops. When stopping send the data to the file that will insert it into bd

<script>
    var estado = true; //estado do cronometro
    var tempo = 0; //tempo atual

    setInterval("mostrar()", 1000);

    function mostrar(){
        if(estado) {
            tempo += 1;
        }
        document.getElementById("res").innerHTML = tempo+"s";
    }

    function play(botao){ //pausa e retoma a contagem
        if(estado) {
            estado = false;
            botao.value = "retomar";
        }
        else {
            estado = true;
            botao.value = "pausar";
        }
    }

    function salvar(){ //envia os segundos para a página que irá salvar o resultado;
        $("#res").load("salvar.php", {tempo:tempo}); //recebe $_POST['tempo'] na pagina com o insert
    }

</script>

<input type="button" value="pausar" onclick="play(this)"/>
<input type="button" value="pausar" onclick="salvar()"/>
<div id="res"></div>

Just to get an idea!

    
16.03.2016 / 21:04