como sumar columna me da como resultado NAN
Publicado por david (7 intervenciones) el 22/01/2020 19:12:18
Hola buen dia tengo un formulario el cual al precionar agregar articulo va desplegando una tabla
con los datos de el articulo lo que quiero realizar es sumar totos los totales al tratar de hacerlo me da NAN o en lugar de sumar los campos se van poniendo al costado derecho
mi codigo es el siguiente
con los datos de el articulo lo que quiero realizar es sumar totos los totales al tratar de hacerlo me da NAN o en lugar de sumar los campos se van poniendo al costado derecho
mi codigo es el siguiente
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function agregarDetalle(idarticulo,codigo,articulo,unidad,precio,impuestos)
{
var cantidad=1;
//var precio=1;
//var precio_venta=1;
if (idarticulo!="")
{
var subtotal=cantidad*precio;
var resultado=subtotal*impuestos;
var total=subtotal+resultado;
//var iva=subtotal*impuesto;
var fila='<tr class="filas" id="fila'+cont+'">'+
'<td><button type="button" class="btn btn-danger" onclick="eliminarDetalle('+cont+')">X</button></td>'+
'<td><input type="hidden" name="codigo[]" value="'+codigo+'">'+codigo+'</td>'+
'<td><input type="hidden" name="idarticulo[]" value="'+idarticulo+'">'+articulo+'</td>'+
'<td><input type="number" name="cantidad[]" id="cantidad[]" value="'+cantidad+'"></td>'+
'<td><input type="hidden" name="unidad[]" value="'+unidad+'">'+unidad+'</td>'+
'<td><input type="number" name="precio[]" id="precio[]" value="'+precio+'"></td>'+
'<td><input type="number" name="impuestos[]" value="'+impuestos+'"></td>'+
//'<td><input type="number" name="resultado[]'+cont+'" value="'+resultado+'"></td>'+
'<td><span name="subtotal" id="subtotal'+cont+'">'+subtotal+'</span></td>'+
//'<td><input type="number" name="total[]" value="'+total+'" disabled="true"></td>'+
'<td><span name="total" id="total'+cont+'">'+total+'</span></td>'+
'<td><button type="button" onclick="modificarSubototales()" class="btn btn-info"><i class="fa fa-refresh"></i></button></td>'+
'</tr>';
cont++;
detalles=detalles+1;
$('#detalles').append(fila);
modificarSubototales();
}
else
{
alert("Error al ingresar el detalle, revisar los datos del artículo");
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function modificarSubototales()
{
var cant = document.getElementsByName("cantidad[]");
var prec = document.getElementsByName("precio[]");
var sub = document.getElementsByName("subtotal");
var tot = document.getElementsByName("total");
//var imp = document.getElementsByName("impuestos[]");
//var res = document.getElementsByName("resultado");
for (var i = 0; i <cant.length; i++) {
var inpC=cant[i];
var inpP=prec[i];
var inpS=sub[i];
// var inpI=imp[i];
var inpT=tot[i];
// var inpR= res[i];
inpS.value=inpC.value * inpP.value;
//inpR=inpS * inpI;
// inpT.value=inpS.value + inpR.value;
document.getElementsByName("subtotal")[i].innerHTML = inpS.value;
}
calcularTotales();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function calcularTotales(){
var sub = document.getElementsByName("subtotal");
//var tot = document.getElementsByName("total");
var total =0;
var totales =0;
for (var i = 0; i <sub.length; i++) {
//total += document.getElementsByName("total[]")[i].value;
total += document.getElementsByName("total")[i].value;
//totales=total;
//total +=("total")
}
$("#total").html("" + total);
$("#total_compra").val(total);
evaluar();
}
Valora esta pregunta
0