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: 25
India

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>

User avatar
indhosting
Posts: 6
Joined: Tue Jan 15, 2019 1:23 pm
India

Re: Pop up to confirm when clicking a HTML link

Post by indhosting » 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:
India

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