Confirm selection after clicking on the hyperlink

So, I have a hyperlink that, when clicked, does an important action (removes something from the database), so I want the confirmation window to be pressed so that they are not mistaken.

My code for the hyperlink:

<a href='*****.php?Number3=1222&AssignedTo=$12331'>[x]</a>

I am not sure about Javascript, and I know that has a big role in this ... Please help? PS The hyperlink URL is random and there are many, so please don't make it work with only one link.

+5
source share
4 answers

to try

<a href='*****.php?Number3=1222&AssignedTo=$12331' onclick="return confirm('Are you sure you want to delete?')" >[x]</a>
+8
source

Give href the class name and set it to something like jQuery / straight JS, and then do the following:

var r=confirm("Are you sure you want to delete?");
if (r==true){
     return true;
{
else {
     return false;
}
0

, , .

<a href="file.php" class="confirm">Link</a>

Then attach an event handler to them:

var links = document.getElementsByClassName('confirm');
for (var i = 0; i < links.length; i++) {
    links[i].onclick = function() {
        return confirm("Are you sure?");
    };
}

Or using jQuery:

$('.confirm').live('click', function(){
    return confirm("Are you sure?");
});
0
source

Here is the answer for the newer jQuery with some additional functionality for those who want to receive custom message acknowledgments.

$('body').on('click', '[data-confirm]', function(){
    var msg = $(this).attr('data-confirm');
    return confirm(msg);
});

You use data verification instead of .confirm. Your HTML looks like this:

<span data-confirm="Are you sure?">delete</span>
0
source

All Articles