Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/01/2012, 07:17
Avatar de kimmy
kimmy
 
Fecha de Ingreso: julio-2008
Mensajes: 841
Antigüedad: 15 años, 10 meses
Puntos: 15
Pregunta sumar input text con variable sin hacer submit

Estoy haciando una nómina de empleados con datos de la bd, logré calcular el sueldo quincenal y el total de deducciones con javascript pero no me funciona el total devengado. Este es mi código javascript:

Código Javascript:
Ver original
  1. function calcula(dias, sueldo_diario, indice) {
  2.       document.getElementById('sueldo_quinc' + indice).value = dias * sueldo_diario;
  3.     }
  4.      
  5. function deducciones(otros_desc, ivss, paro_for, lph, indice2) {
  6.         document.getElementById('total_deducc' + indice2).value = parseFloat(otros_desc) + parseFloat(ivss) + parseFloat(paro_for) + parseFloat(lph);
  7.     }
  8.      
  9. function total_dev(otros_ing, sueldo_quinc, total_deducc, indice3) {
  10.         document.getElementById('total_deveng' + indice3).value = (parseFloat(otros_ing) + parseFloat(sueldo_quinc)) - parseFloat(total_deducc);
  11.     }

y el fomulario:

Código HTML:
Ver original
  1. <form action="nomina_reg.php" method="post" >
  2.     <table width="750" border="0" class="tabla2">
  3.     <tr>
  4.     <td colspan="5" class="td2" bgcolor="#95bce2">UNIDAD EDUCATIVA</td>
  5.     </tr>
  6.     <tr>
  7.     <td colspan="5">NOMINA PARA EL PAGO DE SUELDOS EMPLEADOS</td>
  8.     </tr>
  9.     <tr>
  10.     <td width="7%">Desde:</td>
  11.     <td width="15%">&nbsp;</td>
  12.     <td width="7%">Hasta:</td>
  13.     <td width="16%">&nbsp;</td>
  14.     <td>&nbsp;</td>
  15.     </tr>
  16.     </table>
  17.     <br />
  18.     <table width="750" border="1"  bordercolor="#95bce2"  class="tabla3">
  19.     <tr bgcolor="#95bce2 ">
  20.         <td width="3%" class="td3"></td>
  21.         <td width="3%" class="td3">CI</td>
  22.         <td width="10%" class="td3">APELLIDOS</td>
  23.         <td width="11%" class="td3">NOMBRES</td>
  24.         <td width="4%" class="td3">DIAS</td>
  25.         <td width="8%" class="td3">SUELDO BÁSICO</td>
  26.         <td width="8%" class="td3">SUELDO DIARIO</td>    
  27.         <td width="8%" class="td3">SUELDO B. QUINCENA</td>
  28.         <td width="8%" class="td3">IVSS</td>
  29.         <td width="8%" class="td3">PARO FORSOZO</td>
  30.         <td width="8%" class="td3">LPH</td>
  31.         <td width="8%" class="td3">OTROS INGRESOS</td>
  32.         <td width="8%" class="td3">OTROS DESCUENT</td>
  33.         <td width="8%" class="td3">TOTAL DEDUCCIONES</td>
  34.         <td width="8%" class="td3">TOTAL DEVENGADO</td>
  35.       </tr>
  36.      
  37.       <?php
  38.    $indice = 1;
  39.    $indice2 = 1;
  40.    $indice3 = 1;
  41.    $rs = mysql_query("SELECT * FROM empleados ORDER BY id_empleado ASC");
  42.    while($result = mysql_fetch_array($rs)) {
  43.        $ivss = number_format(($result['sueldo_basico']*4/100),2,'.','');
  44.        $paro_for = number_format(($result['sueldo_basico']*0.5/100),2,'.','');
  45.        $lph = number_format(($result['sueldo_basico']*1/100),2,'.','');
  46.        $sueldo_diario = $result['sueldo_basico']/30;
  47.    ?>
  48.         <tr>
  49.         <td><?php echo $result['id_empleado']; ?><input type="hidden" name="id_empleado[]" value="<?php echo $result['id_empleado']; ?>" /></td>
  50.             <td><?php echo $result['ci']; ?></td>
  51.             <td><?php echo "{$result['papellido']} {$result['sapellido']}"; ?></td>
  52.             <td><?php echo "{$result['pnombre']} {$result['snombre']}"; ?></td>
  53.             <td><input name="dias[]" type="text" id="dias<?php echo $indice; ?>" size="2" value="" onblur="calcula(this.value, '<?php echo $sueldo_diario; ?>', <?php echo $indice; ?>);" /></td>
  54.             <td><?php echo $result['sueldo_basico']; ?></td>
  55.             <td><?php echo $sueldo_diario; ?></td>
  56.             <td><input name="sueldo_quinc[]" type="text" id="sueldo_quinc<?php echo $indice; ?>" size="5" value="" readonly="readonly" /></td>
  57.             <td><?php echo $ivss; ?></td>
  58.             <td><?php echo $paro_for; ?></td>
  59.             <td><?php echo $lph; ?></td>
  60.             <td><input name="otros_ing[]" type="text" id="otros_ing<?php echo $indice3; ?>" size="5" value="" onblur="total_dev(this.value, '<?php echo $sueldo_quinc; ?>', '<?php echo $total_deducc; ?>', <?php echo $indice3; ?>);" /></td>
  61.             <td><input name="otros_desc[]" type="text" id="otros_desc<?php echo $indice2; ?>" size="5" value="" onblur="deducciones(this.value, '<?php echo $ivss; ?>', '<?php echo $paro_for; ?>', '<?php echo $lph; ?>', <?php echo $indice2; ?>);" /></td>
  62.             <td><input name="total_deducc[]" type="text" id="total_deducc<?php echo $indice2; ?>" size="5" value="" readonly="readonly" /></td>
  63.            <td><input name="total_deveng[]" type="text" id="total_deveng<?php echo $indice3; ?>" size="5" value="" readonly="readonly" /></td>
  64.         </tr>
  65.     <?php
  66.        $indice ++;
  67.        $indice2 ++;
  68.        $indice3 ++;
  69.    } // fin de while

cuando lo ejecuto me da en el total el resultado NaN. No se que hago mal????
__________________
Caminando con el corazón partío