Show confirmation box after clicking a HTML link <a> Topic is solved

HTML, PHP, CSS, Javascript, AJAX.............
shravaninetha
Posts: 4
Joined: Tue Jan 15, 2019 8:33 pm
Location: Hyderabad
Mood:
Age: 29

Show confirmation box after clicking a HTML link <a>

Post by shravaninetha » Sat Jan 26, 2019 1:00 pm

i want to display a pop up for my dashboard when a user click delete link.

Code: Select all

<a href="page.php?action=delete&id=$id">Delete</a>

cuehosting
Posts: 8
Joined: Tue Jan 15, 2019 1:23 pm
Has thanked: 2 times
Been thanked: 7 times

Re: Pop up to confirm when clicking a HTML link

Post by cuehosting » Sat Jan 26, 2019 1:38 pm

here are different types of prompting it and you can use that best suits you

Inline Code:

Code: Select all

<a href="page.php?action=delete&id=$id"  onclick="return confirm('Are you sure?')">Delete</a>
Event Listener:

Code: Select all

<a href="page.php?action=delete&id=$id"  class="alert">Delete</a>

<script type="text/javascript">
    var elems = document.getElementsByClassName('alert');
    var confirmIt = function (e) {
        if (!confirm('Are you sure?')) e.preventDefault();
    };
    for (var i = 0, l = elems.length; i < l; i++) {
        elems[i].addEventListener('click', confirmIt, false);
    }
</script>
Jquery:

Code: Select all

<a href="page.php?action=delete&id=$id"  class="alert">Delete</a>

<script type="text/javascript">
    $('.alert').on('click', function () {
        return confirm('Are you sure?');
    });
</script>

Alizeh
Posts: 1
Joined: Wed Apr 03, 2019 5:23 pm
Mood:
Been thanked: 1 time

Re: Pop up to confirm when clicking a HTML link

Post by Alizeh » Wed Apr 03, 2019 5:39 pm

indhosting wrote:
Sat Jan 26, 2019 1:38 pm
here are different types of prompting it and you can use that best suits you

Inline Code:

Code: Select all

<a href="page.php?action=delete&id=$id"  onclick="return confirm('Are you sure?')">Delete</a>
Event Listener:

Code: Select all

<a href="page.php?action=delete&id=$id"  class="alert">Delete</a>

<script type="text/javascript">
    var elems = document.getElementsByClassName('alert');
    var confirmIt = function (e) {
        if (!confirm('Are you sure?')) e.preventDefault();
    };
    for (var i = 0, l = elems.length; i < l; i++) {
        elems[i].addEventListener('click', confirmIt, false);
    }
</script>
Jquery:

Code: Select all

<a href="page.php?action=delete&id=$id"  class="alert">Delete</a>

<script type="text/javascript">
    $('.alert').on('click', function () {
        return confirm('Are you sure?');
    });
</script>
i totally agree with you mate.

Post Reply Previous topicNext topic