I'm trying to calculate hours * value hours = total to pay, but it does not show the result in the total input to be paid
input
<div class="input-field col s12 m4">
<select name="horas" onblur="calcula_porcentaje(this.form)">
<option value="" disabled selected>Cantidad Horas:</option>
<?php
$consulta = $DB_con->query("SELECT * FROM horas ORDER BY id_horas");
while ($linea = $consulta->fetch(PDO::FETCH_ASSOC)) {
?>
<option value="<?php echo $linea['horas'] ;?>"><?php echo $linea['horas'] ;?> Horas</option>
<?php
}
?>
</select>
</div>
<div class="input-field col s12 m4">
<input id="icon_prefix" class="black-text" type="text" name="valor_horas" value="<?php echo $valor_horas; ?>" readonly/>
<label for="cuentas" class="black-text ">Valor Horas:</label>
</div>
<div class="input-field col s12 m4">
<input id="icon_prefix" class="black-text" type="text" name="total_pago"/>
<label for="cuentas" class="black-text ">Total a Pagar:</label>
</div>
function
function calcula_porcentaje(form) {
var horas = form.horas.value;
var valor_horas = form.valor_horas.value;
var total_pago = form.total_pago.value;
if (horas.length === 0) { return; }
if (valor_horas.length === 0 && total_pago.length === 0) { return; }
horas = parseInt (horas);
var resultado = 0;
if (total_pago.length === 0) {
horas = parseInt(horas);
resultado = horas * valor_horas;
form.total_pago.value=resultado;
}
}
debug to the js function