Validate previous data with the new data [closed]

0

I pose the situation, I have a series of records that I can edit and I have a percentage field, so what I want is that at the time of editing I validate that I can not enter a lower percentage than the previous one, I edit and in the the text box appears 20 and if I put 10 do not leave me since it is smaller.

    
asked by Jesus Galeano 18.01.2017 в 22:07
source

1 answer

1

The functionality that I understood the show in the following example, I hope you can serve, greetings.

Look at this example with jquery :

var valorAnterior;
$(document).ready(function() {
  valorAnterior = 0;
  $("#porcentaje").change(function() {
    $(".error").css("display", "none");
    var valorNuevo = parseFloat($(this).val());
    valorNuevo = isNaN(valorNuevo) ? 0 : valorNuevo;
    if (valorAnterior == 0) {
      valorAnterior = valorNuevo;
    } else {
      if (valorNuevo < valorAnterior) {
        $(".error").text("El valor no puede ser Menor que " + valorAnterior);
        $(".error").css("display", "block");
        $("#porcentaje").val(0);

      } else {
        valorAnterior = valorNuevo;
      }
    }
  });
});
.error {
  color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Porcentaje
<input id="porcentaje" />
<div class="error" style="display:none;"></div>
    
answered by 19.01.2017 / 10:56
source