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

222
Views
¿Cómo enviar un valor personalizado al código javascript de sweetalert desde PHP?

Quiero advertir al usuario sobre intentar eliminar un archivo. ¿Cómo puedo transferir algunos detalles a través del html button a este javascript? por ejemplo, cada vez que el usuario eliminará archivos diferentes, el botón debe enviar una identificación de archivo diferente a la fileid de identificación de archivo de la URL.

aquí está el ejemplo .js

 <script> document.getElementById("custom-sa-warning") && document.getElementById("custom-sa-warning").addEventListener("click", function() { Swal.fire({ html: '<div class="mt-3"><lord-icon src="https://cdn.lordicon.com/gsqxdxog.json" trigger="loop" colors="primary:#f7b84b,secondary:#f06548" style="width:100px;height:100px"></lord-icon><div class="mt-4 pt-2 fs-15 mx-5"><h4>Are you Sure ?</h4><p class="text-muted mx-4 mb-0">Are you Sure You want to Delete this Account ?</p></div></div>', showCancelButton: !0, confirmButtonClass: "btn btn-primary w-xs me-2 mb-1", confirmButtonText: "Yes, Delete It!", cancelButtonClass: "btn btn-danger w-xs mb-1", buttonsStyling: !1, showCloseButton: !0 }).then((result) => { if (result.value) { window.location.href = `https://somedimain.com/delete.php?id=fileid` } }); }) </script>

Aquí está el html para iniciar la ventana emergente

 <button type="button" class="btn btn-primary" id="custom-sa-warning">Click me</button>

Ya probé var test = 'https://somedimain.com/delete.php?id=$fileid';

 if (result.value) { var example = test; window.location.href = example }

, funciona, pero ¿cómo puedo cambiar este valor de var test desde un botón?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Agregue el atributo data-fileId a su botón y cuando haga clic en el botón, haga clic en los botones 'data-fileId'. debería ser así

html:

 <button type="button" class="btn btn-primary" id="custom-sa-warning" data-fileId="write your fileId">Click me</button>

js:

 <script> document.getElementById("custom-sa-warning") && document.getElementById("custom-sa-warning").addEventListener("click", function(event) { var el = event.target || event.srcElement; var fileId = el.getAttribute('data-fileId'); Swal.fire({ html: '<div class="mt-3"><lord-icon src="https://cdn.lordicon.com/gsqxdxog.json" trigger="loop" colors="primary:#f7b84b,secondary:#f06548" style="width:100px;height:100px"></lord-icon><div class="mt-4 pt-2 fs-15 mx-5"><h4>Are you Sure ?</h4><p class="text-muted mx-4 mb-0">Are you Sure You want to Delete this Account ?</p></div></div>', showCancelButton: !0, confirmButtonClass: "btn btn-primary w-xs me-2 mb-1", confirmButtonText: "Yes, Delete It!", cancelButtonClass: "btn btn-danger w-xs mb-1", buttonsStyling: !1, showCloseButton: !0 }).then((result) => { if (result.value) { window.location.href = "https://somedimain.com/delete.php?id=" + fileId } }); }) </script>
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!