<script type="text/javascript">
function ConfirmDelete()
{
if (confirm("Delete Account?"))
location.href='linktoaccountdeletion';
}
</script>
echo '<input type="button" onclick="ConfirmDelete()" value="DELETE ACCOUNT">';
JavaScript Confirm before deletion with PHP/MYSQL [closed]
-
11-04-2022 - |
سؤال
I have tried a number of examples here but I can get my code to actually show a popup window before deletion. The code I use can be found here:
echo "<td><button class='btn'><a href=\"deleteuserExecute2.php?login=" .$login. "\" onClick=\"return confirm(\'Delete this Account?\')\"; >DELETE ACCOUNT </a></button></td>";
المحلول 2
نصائح أخرى
You just need to use the onclick
method for your link or button:
<a href="DELETE_PAGE" onClick="return confirm('Delete This account?')">Delete Account</a>
try this
<form action="url/to/delation_page" onSubmit="return confirm('are you sure?')">
</form>
Just say
onclick="return confirm('Are you sure you want to delete?')"
^^^^^^ --> this is very important step...
javascript confirmation
function doConfirm(id)
{
var ok = confirm("Are you sure to Delete?")
if (ok)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
window.location = "create_dealer.php"; // self page
}
}
xmlhttp.open("GET", "delete_dealer.php?id=" + id);
xmlhttp.send();
}
}
button for delete
<input type="button" onclick="doConfirm();"/>
if u use on-click the data will be deleted but to view result u have to refresh the page manually instead use onSubmit="return confirm('are you sure?')"
think it helps !
لا تنتمي إلى StackOverflow