Skip to content
Advertisement

Sweet Alert Delete Confirmation with a href

Im using PHP, and Sweet alert for a delete confirmation. Problem is that it is deleting before showing the sweet alert.

This is my HTML(which is using PHP in it).

JavaScript

This is my sweet alert

JavaScript

}

The problem is, its not showing the sweet alert, its just going straight to the URL. Do I need to do a form and prevent submits or something like that?

Advertisement

Answer

The problem is that click on anchor element has a default behavior. You could use event.preventDefault() to prevent the redirection and navigate manually based on you logic with window.location.href='url'

<div class="delete"><a onclick="confirmation(event)" href="'.URLROOT.'/dashboards/delete_note/'.htmlspecialchars($note->note_id).'/'.$data['table'] .'"><i class="far fa-trash-alt"></i></a></div>

and in js

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement