Por que el if me da el siguiente resultado
Publicado por Cristopher (1 intervención) el 30/09/2020 00:20:06
Buen día, tengo la siguiente funcion en un jsp
se supone que si el stock es menor o igual que el minStock me cambia de color, de lo contrario no lo hace, pero me cambia el color de todo, por lo que al parecer me devuelve que Stock siempre es igual a minStock, supongo que el tipo de dato no es el correcto, ¿alguien me podría explicar como hacer esa comparación correctamente? soy estudiante y no comprendo del todo como funciona esto, les agradecería su respuesta, el codigo de la tabla de donde saco los datos es el siguiente:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<script language="javascript">
function alerta() {
let Stock = document.querySelectorAll('#Stock');
let minStock = document.querySelectorAll('#minStock');
for(i=0; i<Stock.length ; i++)
{
if (Stock[i] <= minStock[i]){
Stock[i].style.color="#FF0000";
}
}
}
</script>
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
40
41
42
43
44
45
46
47
48
49
<table id="datos" number-per-page="4" current-page="" class="table table-striped table-sm ">
<thead>
<tr>
<th>Id</th>
<th>Nombre</th>
<th >Descripción</th>
<th>Costo</th>
<th>Precio</th>
<th>Stock</th>
<th>Stock Mín.</th>
<th>Stock Máx.</th>
<th>Id Prov.</th>
<th>Id Ca.</th>
<th>Imagen</th>
<th>Actualizar / Eliminar</th>
</tr>
</thead>
<tbody>
<c:forEach var="p" items="${lista}">
<tr id="resConsulta">
<td>${p.getId()}</td>
<td class="text-break" style="max-width: 150px;">${p.getNombre()}</td>
<td class="text-break" style="max-width: 150px;">${p.getDescripcion()}</td>
<td>${p.getPrecio_compra()}</td>
<td>${p.getPrecio_venta()}</td>
<td id="Stock">${p.getStock()}</td>
<td id="minStock">${p.getMin_stock()}</td>
<td>${p.getMax_stock()}</td>
<td>${p.getProveedor_idProveedor()}</td>
<td>${p.getCategoria()}</td>
<td><img src="${p.getFoto()}"width="40" height="40"></td>
<td>
<div class="btn-group " role="group " aria-label="Basic example ">
<button type="button" class="btn btn-outline-warning" onclick="location.href='./Controlador?accion=EditarProducto&id=${p.getId()}'">
<img src="img/icons/actualizar.png"> Actualizar
</button>
<button id="deleteItem" type="button" class="btn btn-outline-danger" onclick="location.href='./Controlador?accion=EliminarProducto&id=${p.getId()}'">
<img src="img/icons/eliminar.png">Eliminar
</button>
</div>
</td>
</tr>
</c:forEach>
</tbody>
</table>
Valora esta pregunta


0