Ramesh Pareek
Ramesh Pareek

Reputation: 1669

javascript confirm dialog keeps appearing sometimes

Hello I'm using confirm dialog to ensure a user action. But the confirm dialog keeps appearing again and again while I don't see in my code anything which is triggering this. Is it a bug? or am I doing something wrong?

$('#table_trans tbody').on('click', 'tr td button', function() {
    var trans_id = $($(this).parents(':eq(1)')[0].childNodes[0]).html();
    var r = confirm("Sure!");

    if (r == true) {
        $.ajax({
            url: '?r=transactions/ajaxdelete',
            data: {
                id: trans_id
            },
            success: function(response) {
                $.notify(response, "error");
            }
        });
        $($(this).parents(':eq(1)')).remove();

    } else {
        alert("Action Cancelled!");
    }
});

One more thing to add, It happens only sometimes that the Javascript confirm dialog keeps appearing. sometimes it behaves correctly, sometimes it appears twice, but sometimes infinitely.

UPDATE

As suggested by Parag Bhayani, Here is the javascript that adds a row to the table #table_trans

// msg is a json response received by making an ajax call

for (var i = 0, l = msg.length; i < l; i++) {
                    var rowz = "<tr><td>" + msg[i].id +"</td><td>"+msg[i].account_no+"</td><td>" + msg[i].date_of_transac +"</td><td>"+msg[i].description+"</td><td>"+msg[i].amount+"</td><td><button id=\"delete_trans\">Delete</button></td><tr>";
                    tbl_html = tbl_html + rowz;

            }

// sorry for the discomfiture .... but please scroll to extreme right to see the button, clicking which is triggering the event.

Upvotes: 1

Views: 160

Answers (1)

Parag Bhayani
Parag Bhayani

Reputation: 3330

This could be happen only if your event is registered multiple times, so one case for that could be causing this issue is that, event registeration code is in loop then your event might have registered n number of times.

Upvotes: 1

Related Questions