Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
¿Cómo agregar un mensaje de confirmación antes de eliminar?

Estoy tratando de agregar un mensaje de confirmación antes de eliminar datos en mi tabla. Pero no sé cómo y dónde poner el código. Intenté buscar otros códigos pero no funciona.
Aquí está mi código:

 <?php $a = 0?> <?php while ($row = mysqli_fetch_array($res)) { echo "<tr id=".$a++."> <th scope='row' class='row-data'>".$row['user_id']."</th> <td class='row-data'>".$row['full_name']."</td> <td class='row-data'>".$row['user_name']."</td> <td><input type='button' value='EDIT' onclick='editUser()'' /></td> <td><input type='button' value='DELETE' onclick='deleteUser()' /></td> </tr> </tbody>"; }; ?> function deleteUser() { var rowId = event.target.parentNode.parentNode.id; //this gives id of tr whose button was clicked var data = document.getElementById(rowId).querySelectorAll(".row-data"); /*returns array of all elements with "row-data" class within the row with given id*/ var uID = data[0].innerHTML; document.getElementById("toBeEdit").value = uID; document.getElementById("taskStatus").value = 'delete'; //alert("ID: " + uID); const form = document.getElementById('editForm'); form.submit(); } </script>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede usar el método incorporado confirm() en su función deleteUser() . Por favor, vea el código a continuación,

 function deleteUser() { if(confirm('Are you sure want to delete user?')){ var rowId = event.target.parentNode.parentNode.id; //this gives id of tr whose button was clicked var data = document.getElementById(rowId).querySelectorAll(".row-data"); /*returns array of all elements with "row-data" class within the row with given id*/ var uID = data[0].innerHTML; document.getElementById("toBeEdit").value = uID; document.getElementById("taskStatus").value = 'delete'; //alert("ID: " + uID); const form = document.getElementById('editForm'); form.submit(); } }

El método confirm() muestra un cuadro de diálogo con un mensaje, un botón Aceptar y un botón Cancelar.

El método confirm() devuelve verdadero si el usuario hizo clic en "Aceptar", de lo contrario, falso.

about 4 years ago · Juan Pablo Isaza Report

0

Debe agregar este código para incluir su función de eliminación

 if(window.confirm("do you want delete this data")){ -->your code with js<-- }else{ return false; }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!