I have a table HTML
in which I want to perform mathematical operations, but I do not get to execute the code.
function formula() {
var cantidad = document.mytable.cantidad.value;
var precio_unitario = document.mytable.precio_unitario.value;
var iva = document.mytable.iva.value;
try{
cantidad = (isNaN(parseInt(cantidad)))? 0 : parseInt(cantidad);
iva = (isNaN(parseInt(iva)))? 0 : parseInt(iva);
precio_unitario = (isNaN(parseInt(precio_unitario)))? 0 : parseInt(precio_unitario);
total = (isNaN(parseInt(total)))? 0 : parseInt(total);
document.mytable.total.value = (cantidad*iva*precio_unitario);
}
catch(e) {}
}
<table name="mytable" id="mytable" class="table table-bordered table-hover">
<thead>
<tr>
<th width="5%">Cantidad</th>
<th width="18%">Descripción del artículo</th>
<th width="5%">Precio Unitario</th>
<th width="5%">%DTO</th>
<th width="5%">IVA</th>
<th width="7%">Precio Total</th>
<th width="12%">Inspección de recepción</th>
<th width="12%">Comentarios</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" id="cantidad" name="cantidad" class="form-control" onKeyUp="formula()"></td>
<td><input type="text" id="artiuclo" name="articulo" class="form-control">
</td>
<td><input type="text" id="precio_unitario" name="precio_unitario" class="form-control" onKeyUp="formula()"></td>
<td><input type="text" id="descuento_porcentaje" name="descuento_porcentaje" class="form-control"></td>
<td><input type="text" id="iva" name="iva" class="form-control">
</td>
<td><input type="text" id="precio_total" name="precio_total" class="form-control" onKeyUp="formula()">
</td>
<td><input type="text" id="inspeccion" name="inspeccion" class="form-control"></td>
<td><input type="text" id="comentarios" name="comentarios" class="form-control"></td>
</tr>
<th>Total</th>
<td><input type="text" id="total" name="total" class="form-control"></td>
</tbody>
</table>