How do I manipulate team values in my JS?

Asked

Viewed 44 times

0

I need to perform a calculation with input values like time in my JS using jquery, how do I do that? is there any library ready?

<label for="">Inicio</label>
<div class="form-group">
    <input type="time" class="form-control" id="inicio">
</div>

<label for="">Fim</label>
<div class="form-group">
    <input type="time" class="form-control" id="fim">
</div>

$(function() {
    $('#calcular').click(function(){

        var inicio = $('#inicio').val();
        var fim = $('#fim').val();
        var ciclo = $('#ciclo').val();


    });

});
  • 2

    Which calculation do you want to make, sum all values, divide?

1 answer

0


$('#btnSoma').click(function(){

    var inicio = $('#inicio').val();
    var iniSplit = inicio.split(':');
    var inic1 = iniSplit[0];
    var inic2 = iniSplit[1];
    var fim = $('#fim').val();
    var fimSplit = fim.split(':');
    var fim1 = fimSplit[0];
    var fim2 = fimSplit[1];
    var ciclo = $('#ciclo');

    var somaInicio = Number(inic1) + Number(fim1);
    var somaFim = Number(inic2) + Number(fim2);
    var soma = somaInicio+ ' : ' +somaFim;
        
    ciclo.val(soma);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<label for="">Inicio</label>
<div class="form-group">
    <input type="time" class="form-control" id="inicio">
</div>

<label for="">Fim</label>
<div class="form-group">
    <input type="time" class="form-control" id="fim">
</div>

<label for="">Ciclo</label>
<div class="form-group">
    <input type="text" class="form-control" id="ciclo">
    <button type="button" id="btnSoma">Somar</button>
</div>

Browser other questions tagged

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