Show confirmation box after clicking a HTML link <a> Topic is solved
-
- Posts: 4
- Joined: Tue Jan 15, 2019 8:33 pm
- Location: Hyderabad
- Mood:
- Age: 29
Show confirmation box after clicking a HTML link <a>
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>
-
- 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
here are different types of prompting it and you can use that best suits you
Inline Code:
Event Listener:
Jquery:
Inline Code:
Code: Select all
<a href="page.php?action=delete&id=$id" onclick="return confirm('Are you sure?')">Delete</a>
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>
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>
Re: Pop up to confirm when clicking a HTML link
i totally agree with you mate.indhosting wrote: ↑Sat Jan 26, 2019 1:38 pmhere are different types of prompting it and you can use that best suits you
Inline Code:Event Listener:Code: Select all
<a href="page.php?action=delete&id=$id" onclick="return confirm('Are you sure?')">Delete</a>
Jquery: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>
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>