带有if语句的html中的确认对话框

时间:2014-12-13 18:33:38

标签: javascript php html html5 forms


我想在用户想要删除时发出确认消息
选项1 :如果是,则从数据库中删除学生,并将用户重定向到 index.php

选项2:如果不是,则应将用户重定向到show.php

我试过了,但是我无法满足选项2的要求 这是我的代码:

<body>
<center><h1>Delete record</h1></center>
<center><form action="del.php" method="post" onsubmit="return confirm('Are you sure you want to delete?')">
Enter the ID for student you want to delete :
</br><input type="text" name="id"/>        </br>
</br>
<input id="button" type="submit" value="Delete" style="width: 219px"/> </br>
<a href = "change.html">Back</a>


</form></center>
</body>



 更新

我找到了解决方案。对于任何寻求它的人。谢谢你的时间

<html>

<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

function delfunction(form) {
        if (confirm("Are you sure you want to submit the form?")) {
            form.submit();
        }

        else {
           window.location = 'show.php';
        }
    }
   </script>
<title>Delete</title>
</head>

<body>
<center><h1>Delete</h1></center>


<center><form action="del.php" method ="post" >

Enter the ID for student you want to delete :<br />
    <input type="text" name="id"/><br />
    </br>


<input type="button" onclick="delfunction(this.form);" value="Delete !" style="width: 115px"/><br />
    <a href = "change.html">Back</a>


</form></center>
</body>

</html>

1 个答案:

答案 0 :(得分:0)

<script type="text/javascript">
function areyousure(id)
{
    jConfirm("Are you sure you want to delete?", "Delete Message", function (callback) {
        if (callback) {
           window.location='delete_student.php?id='+id;
        } else {
            return false;
        }
    });
}
</script>

<form onclick="return areyousure('2');">