#The reset only works on the first row. By adding a second row, the reset deletes the first row when the condition is met.
with this code
document.getElementsByClassName("kmactual")[0].value = "";
it resets me.
who is in this condition
MENSAJE = "EL KILOMETRAJE ACTUAL TIENE QUE SER MAYOR QUE EL KILOMETRAJE ANTERIOR ..!!";
$("#mensaje").html(MENSAJE);
$("#modalMensaje").modal('show');
document.getElementsByClassName("kmactual")[0].value = "";
This code deletes the data of an input when it is not fulfilled. As I wrote above, when entering a lower value in the first row, the message appears and the entered data is deleted. When adding another row and inserting the data that does not comply, it deletes the one from the first row
<script>
$("#tablaprueba").on('change', 'input.kmactual', function() {
var contenido = document.getElementsByClassName("kilometraje_actual")[0].value;
var contenido_km_motor = document.getElementsByClassName("km_motor")[0].value;
var contenido_km_caja = document.getElementsByClassName("km_caja")[0].value;
var contenido_km_diferencial = document.getElementsByClassName("km_diferencial")[0].value;
var contenido_km_adblue = document.getElementsByClassName("km_adblue")[0].value;
var $select = $(this), // Obtenemos el select modificado
$tr = $select.closest('tr'), // Buscamos el tr del select
valor = $select.val();
var calculo_km_motor=parseInt(contenido_km_motor) + parseInt(5000);
var calculo_km_caja=parseInt(contenido_km_caja) + parseInt(5000);
var calculo_km_diferencial=parseInt(contenido_km_diferencial) + parseInt(5000);
var calculo_km_adblue=parseInt(contenido_km_adblue);
if (parseInt(valor) > parseInt(contenido)) {
if (parseInt(valor) < parseInt(calculo_km_motor)) {
if (parseInt(valor) < parseInt(calculo_km_caja)) {
if (parseInt(valor) < parseInt(calculo_km_diferencial)) {
if (parseInt(valor) < parseInt(calculo_km_adblue) || parseInt(calculo_km_adblue) >= 0) {
var total = valor - contenido;
$tr.find("input.diferencia_km").val(total);
}else{
MENSAJE = "EL KILOMETRAJE ACTUAL TIENE QUE SER MENOR QUE EL KILOMENTRAJE DE LA MANTENCION DEL CAMBIO DE FILTRO DE ADBLUE. SI YA REALIZO LA MANTENCION DEL CAMBIO DE FILTRO DE ADBLUE. VERIFICAR SI INGRESO LA MANTENCION EN EL REGISTRO DE MANTENCIONES";
$("#mensaje").html(MENSAJE);
$("#modalMensaje").modal('show');}
}else{
MENSAJE = "EL KILOMETRAJE ACTUAL TIENE QUE SER MENOR QUE EL KILOMENTRAJE DE LA MANTENCION DEL CAMBIO DE ACEITE DEL DIFERENCIAL. SI YA REALIZO LA MANTENCION DEL CAMBIO DE ACEITE DEL DIFERENCIAL. VERIFICAR SI INGRESO LA MANTENCION EN EL REGISTRO DE MANTENCIONES";
$("#mensaje").html(MENSAJE);
$("#modalMensaje").modal('show');
}
}else{
MENSAJE = "EL KILOMETRAJE ACTUAL TIENE QUE SER MENOR QUE EL KILOMENTRAJE DE LA MANTENCION DEL CAMBIO DE ACEITE DE LA CAJA. SI YA REALIZO LA MANTENCION DEL CAMBIO DE ACEITE DE LA CAJA. VERIFICAR SI INGRESO LA MANTENCION EN EL REGISTRO DE MANTENCIONES";
$("#mensaje").html(MENSAJE);
$("#modalMensaje").modal('show');
}
}else{
MENSAJE = "EL KILOMETRAJE ACTUAL TIENE QUE SER MENOR QUE EL KILOMENTRAJE DE LA MANTENCION DEL CAMBIO DE ACEITE DEL MOTOR. SI YA REALIZO LA MANTENCION DEL CAMBIO DE ACEITE DEL MOTOR. VERIFICAR SI INGRESO LA MANTENCION EN EL REGISTRO DE MANTENCIONES";
$("#mensaje").html(MENSAJE);
$("#modalMensaje").modal('show');
}
}else{
MENSAJE = "EL KILOMETRAJE ACTUAL TIENE QUE SER MAYOR QUE EL KILOMETRAJE ANTERIOR ..!!";
$("#mensaje").html(MENSAJE);
$("#modalMensaje").modal('show');
document.getElementsByClassName("kmactual")[0].value = "";
}
});
</script>
I would say instead of this:
you need to do this:
because if you look at the start of the whole function:
that
$(this)
function's is already representing theinput.kmactual
one receiving that eventchange
, so you can now use it directly instead of trying to use the getElementsByClassName function .jquery's val() function is similar to javascript's value property.
Said getElementsByClassName function contains all the elements of that class that you pass to it as a parameter ( kmactual ), and it will not know where you are if you do not tell it, and in your case the error is that you tell it that it is the first element with the class
kmactual
by adding the index number with this syntax[0]
, and that's why it changes the first one only.