First, im sorry if my english so bad :v I have a problem, i have many data, and i want to delete some data with sweet alert delete confirmation, but this delete confirmation just working in the last data (last row), if i want to delete data in first row or middle, thats sweet alert its not working, but my data still deleted, i hope someone wanna help me, thanks
i use codeigniter and this ss of my code
This part of code
<tbody>
<?php foreach ($karyawan as $karyawan): ?>
<tr>
<td>
<?php echo $karyawan->IDKaryawan; ?>
</td>
<td>
<?php echo $karyawan->NamaKary; ?>
</td>
<td>
<?php echo $karyawan->NoHp; ?>
</td>
<td>
<?php echo $karyawan->alamat; ?>
</td>
<td>
<?php echo $karyawan->tanggalmasuk; ?>
</td>
<td>
<a href="<?php echo site_url('karyawan/detailkaryawan.php?id='.$karyawan->IDKaryawan); ?>" title="Detail Karyawan"><img width="24" height="24" src="<?php echo base_url('img/detail.png'); ?>" /></a>
<a href="<?php echo site_url('karyawan/editkaryawan?id='.$karyawan->IDKaryawan); ?>" title="Edit Karyawan"><img width="20" height="20" src="<?php echo base_url('img/edit.png'); ?>"/></a>
<a href="<?php echo site_url('karyawan/hapuskaryawan/'.$karyawan->IDKaryawan); ?>" id="sa-params" title="Hapus Karyawan"><img width="20" height="20" src="<?php echo base_url('img/hapus.png'); ?>" /></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
and this my js
$('#sa-params').on("click", function(e){
e.preventDefault();
var abc = $(this).attr('href');
swal({
title: "Anda Yakin?",
text: "Data Yang Sudah Terhapus Tidak Bisa Dikembalikan Lagi!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Ya, Hapus!",
cancelButtonText: "Jangan Hapus!",
closeOnConfirm: false,
closeOnCancel: false
}, function(isConfirm){
if (isConfirm) {
swal("Terhapus!", "Data Berhasil Dihapus.", "success");
setTimeout(function(){ window.location.replace = abc; }, 2000);
} else {
swal("Cancelled", "Data Tidak Jadi Dihapus :)", "error");
}
});
});
Thanks for helping me :)
It's probably happend, because you are using id instead of class in your link.
Change id="sa-params"
to class="sa-params"
in your anchor and
$('#sa-params').on("click", function(e){
//your code
});
to
$('.sa-params').on("click", function(e){
//your code
});
in javascript