suma de valores con jquery
Publicado por alvaro (1 intervención) el 24/07/2019 22:20:26
tengo una tabla la cual necesito sumar sus valores. lo puedo sumar la primera linea, las demas se suman a la primera linea. osea, solo sumo la primera linea. necesito que la suma se realice en cada campo por separado. gracias por la ayuda.
aqui les dejo mi html, jquery y php donde recibo los datos
aqui les dejo mi html, jquery y php donde recibo los datos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function sumar() {
var suma = 0;
//llamamos la clase notas
//$('.notas2').each(function() {
$('form').find('.notas2').each(function() {
if (isNaN(parseFloat($(this).val()))) {
suma += 0;
} else {
suma += parseFloat($(this).val());
}
});
//alert(total);
document.getElementById('sumaTotal').innerHTML = suma;
}
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
<table class="table table-bordered table-condensed table-hover" id="tablaRegistro">
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Apellido</th>
<th>P1</th>
<th>P2</th>
<th>P3</th>
<th>P4</th>
<th class='valores' scope="row">Suma</th>
<th>%Promedio</th>
$cont=1;
while ($registroAsistencia =mysqli_fetch_row($consulta_tabla_estudiante))
{
$id=$registroAsistencia[0];
<tr>
<!--llamamos el id, nombre y apaellido de la bd-->
echo "<td><input type='text' class='notas2 form-control input-sm input' size='1px' name='notas[$id]' id='p1' onChange='sumar();'></td>
<td><input type='text' class='notas2 form-control input-sm input' size='1' name='notas[$id]' id='p2' onChange='sumar();'></td>
<td><input type='text' class='notas2 form-control input-sm input' size='1' name='notas[$id]' id='p3' onChange='sumar();'></td>
<td><input type='text' class='notas2 form-control input-sm input' size='1' name='notas[$id]' id='p4' onChange='sumar();'></td>
<td><span id='sumaTotal' size='1' class='sumaTotal'><input type='text' id='sumaTotal' name='sumaTotal' size='1' class='form-control input-sm input' readonly=''><span></td>
<td><span id='promedio'><input type='text' id='promedio' name='promedio' size='1' class='form-control input-sm input' readonly=''><span></td>
}
<button class='btn btn-success' data-target='bEnviar' value="bEnviar" name="bEnviar" id="bEnviar" onclick="porcentaje();">GUARDAR</button>
Valora esta pregunta


0