Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

236
Vistas
Delete row in table before alert box pop up

I have a table with a button to delete rows, and there is one column in the table that would check for duplicate inputs. The delete function and the duplicate-checking function are working fine. But if I have a duplicate in rows 1 and 5, and then I try to delete row 3, the alert message will pop up before row 3 is disappeared. The result and the alert message show correctly as "Row 1 and row 4 are duplicate!" but the table still has row 5 before I click "OK" in the alert box (i.e. row 5 will be removed once I click "OK").

function Delete_Row(r) {
    var i = r.parentNode.parentNode.rowIndex;
    document.getElementById("Settlement_Table").deleteRow(i);
    for (var i = 1; i< document.getElementById("Settlement_Table").rows.length; i++){
        document.getElementById("Settlement_Table").rows[i].cells[0].innerHTML = i;
    }
    myFunction();
}


function myFunction() {
  var x = document.getElementsByName("Material[]");
  var total_rows = document.getElementById("Settlement_Table").rows.length-1;
  for(var i=0; i<total_rows-1; i++){
      for(var j=i+1; j<total_rows; j++){
          if(x[i].value==x[j].value){
              alert("Row "+ (i+1) + "and row " + (j+1) + " are duplicate!");
          }
      }
  }
}

By the order, the deleteRow(i) function should delete the row and the innerHTML() should update the cell before alert(message) pop up. But somehow the message shows before the table display update. I'm thinking it might be the priority issue with these functions but not really sure. Thank you ahead for any help.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda