does not load result in the input

0

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

    
asked by yoclens 13.10.2018 в 06:36
source

1 answer

0

a migo gave me the solution attached to it

function calcula_porcentaje(horas) {
  //alert(horas);
  var valor_horas = document.form.valor_horas.value;
  var total = horas * valor_horas;
  document.form.total_pago.value = total;
 }


 modificar linea de select 
 <select name="horas"  onblur="calcula_porcentaje(this.form)"> 
 por 
 <select name="horas" onchange="calcula_porcentaje(this.value)">
    
answered by 13.10.2018 / 16:33
source