I have several input
in a table in which only numbers are accepted, I have created a function to verify that they are greater than zero or that they are different from empty after losing the focus, the javascript
code I use for that control is:
function cambiaCantidad(){
if (document.getElementById("tabProd").rows[indice_fila_tabla].cells[3].getElementsByTagName('input')[0].value!=='') {
var valorCelda=document.getElementById("tabProd").rows[indice_fila_tabla].cells[3].getElementsByTagName('input')[0].value;
if (valorCelda>0){
cambiaValores();
}
else{
alert("La cantidad tiene que ser mayor a cero");
document.getElementById("tabProd").rows[indice_fila_tabla].cells[3].getElementsByTagName('input')[0].value=1;
cambiaValores();
}
}
else{
alert("La cantidad es requerida");
document.getElementById("tabProd").rows[indice_fila_tabla].cells[3].getElementsByTagName('input')[0].value=1;
cambiaValores();
}
}
My question is: If the input has a value and then I change it to zero or empty, how can I get it back to the previous value I had, that is, if I had the number 1 and then I change it to zero so that it returns to the previous value (one)