Calculation with Inputs in JavaScript

3
function IBUTG() {
    $tt = $('[name=tempo_trabalho]');
    $vt = $('[name=valor_ibutg_trabalho]');
    $td = $('[name=tempo_descanso]');
    $vd = $('[name=valor_ibutg_descanso]');

    $ibutg = (($tt * $vt) + ($td * $vd)) / 60;

    $('[name=ibutg_calculado]').val($ibutg);
}

I'm getting NaN while performing this function, what can it be? The values of the inputs are in the format 99.9

    
asked by anonymous 10.01.2017 / 18:41

1 answer

6

The .val() was missing at the end

function IBUTG() {
    $tt = parseFloat($('[name=tempo_trabalho]').val());
    $vt = parseFloat($('[name=valor_ibutg_trabalho]').val());
    $td = parseFloat($('[name=tempo_descanso]').val());
    $vd = parseFloat($('[name=valor_ibutg_descanso]').val());

    $ibutg = (($tt * $vt) + ($td * $vd)) / 60;

    $('[name=ibutg_calculado]').val($ibutg);
}
    
10.01.2017 / 18:44