JavaScript Confirm before deletion with PHP/MYSQL

2019-03-16 18:23发布

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:

6条回答
小情绪 Triste *
2楼-- · 2019-03-16 18:44

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 !

查看更多
Explosion°爆炸
3楼-- · 2019-03-16 18:55

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>
查看更多
对你真心纯属浪费
4楼-- · 2019-03-16 18:56

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();"/>
查看更多
一夜七次
5楼-- · 2019-03-16 19:05

Just say

onclick="return confirm('Are you sure you want to delete?')"
         ^^^^^^ --> this is very important step...
查看更多
爱情/是我丢掉的垃圾
6楼-- · 2019-03-16 19:09
  <script type="text/javascript">
      function ConfirmDelete()
      {
            if (confirm("Delete Account?"))
                 location.href='linktoaccountdeletion';
      }
  </script>


  echo '<input type="button" onclick="ConfirmDelete()" value="DELETE ACCOUNT">';
查看更多
贼婆χ
7楼-- · 2019-03-16 19:09

try this

 <form action="url/to/delation_page" onSubmit="return confirm('are you sure?')">

</form>
查看更多
登录 后发表回答