doudeng9425 2012-04-02 05:48
浏览 46
已采纳

单击确认框终止php表单操作

We alert user using this javascript, now i want to add this functionality to my html form, which sends the data using the post method to my php form processing page.

Now what i want is to terminate the action if the user presses cancel button, it means all the data which has been sent using the post method should not be sent and the person would not be able to process the form until and unless he/she clicks the OK button. So is it possible? Or it is just some idiot question?

<html>
<head>
<script type="text/javascript">
function show_confirm()
{
var r=confirm("Press a button!");
if (r==true)
  {
  alert("You pressed OK!");
  }
else
  {
  alert("You pressed Cancel!");
  }
}
</script>
</head>
<body>

<input type="button" onclick="show_confirm()" value="Show a confirm box" />

</body>
</html>
  • 写回答

2条回答 默认 最新

  • dqybeh2884 2012-04-02 06:10
    关注

    Call the confirm on form submit, not on button click, and change the button to a submit button:

    <form onsubmit="return show_confirm();">
        <input type="text" name="test" value="test"><br>
        <input type="submit" value="Show a confirm box">
    </form>
    

    Add a return false; if cancel has been clicked:

    function show_confirm() {
        var r=confirm("Press a button!");
        if (r===true) {
            alert("You pressed OK!");
        } else {
            alert("You pressed Cancel!");
            return false;
        }
    }
    

    Also see my example.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看