I have jquery code to delete data row by row in my table view. When the user click delete icon, conformation box is popup and have "Yes" and "No" button. If "Yes" the row is delete, if "No" close the conformation box and do nothing. The problem is, let say I have 2 row data like this:-
<tr bgcolor=#ACACAC id='ak1'>
<td align='center'>1.</td>
<td>Data 1</td>
<td>...</td>
<td>...</td>
<td>...</td>
<td align='center'>
<img src='image/DocEdit.png' class='editData' id='ID_16'> <img src='image/DocDelete.png' **class='deleteData'** id='**ID_16**'>
</td>
</tr>
<tr bgcolor=#6D6D6D id='ak1'>
<td align='center'>2.</td>
<td>Data 2</td>
<td></td>
<td></td>
<td></td>
<td align='center'>
<img src='image/DocEdit.png' class='editData' id='ID_17'> <img src='image/DocDelete.png' **class='deleteData'** id='**ID_17**'>
</td>
</tr>
So, when I click delete on Data 1, the ID_16 is past to jquery code. Than I click "No" on conformation box. After that, I click delete on Data 2. Now I click "Yes" on conformation box. Data ID_17 deleted from DB, buat after delete ID_17, my jquery will loop and delete ID_16 and all the data that I try to delete before. It's like queue the delete action for the data that I choose "No" on conformation box. Below is my jquery code.
//.deleteData is class for delete button
$('.deleteData').click(function(){
var idData=$(this).attr('id'); //get data id to delete
//Fade in the Popup for conformation delete
$('#cfm-box').fadeIn(300);
//Set the center alignment padding + border see css style
var popMargTop = ($('#cfm-box').height() + 24) / 2;
var popMargLeft = ($('#cfm-box').width() + 24) / 2;
$('#cfm-box').css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});
// Add the mask to body
$('body').append('<div id="mask"></div>');
$('#mask').fadeIn(300);
//if button no click, do nothing
//#no refer to the button ID no.
$('#no').click(function(){
$('#mask , .cfm-popup').fadeOut(300 , function() {
$('#mask').remove();
});
});//end #no
//if yes click, delete data from db
//#yes refer to the button ID yes.
$('#yes').click(function(){
//parameter to send for delete WHERE statement
var tahun = $('#tahunSemasa').val();
var suku = $('#sukuSemasa').val();
var dataString = "tahun="+tahun+"&suku="+suku+"&id="+idData+"&action=delete";
$.ajax({
type: "POST",
url: "prestasiProses.php",
data: dataString,
cache: false,
success: function(html)
{
alert(html);
if(html=='true')
{
window.location.href="main.php?a=31&tahun="+tahun+"&suku="+suku+"&act=delete";
}
else
{
alert("Failed!");
}
}
});
$('#mask , .cfm-popup').fadeOut(300 , function() {
$('#mask').remove();
});
});//end #yes
});//end .deleteData
Any ideas why this code loop like that?
Thanks for the help
yesandnoclick events from insidedeleteDataclick event.