doushishi2415 2013-06-26 03:50 采纳率: 0%
浏览 24
已采纳

Javascript确认以相同的形式删除和编辑

I have two submit buttons on the same form for edit and delete and I want to make delete confirmation alert. I've tried but this only work yes however I select "no/cancel" in delete confirmation. What should I do ?

This is the form

<form name="form" method="POST" action="update.php">
//form code
<input name="update_button" type="submit" value="Update" />
<input type="submit" name="delete_button" onClick="javascript:confirmDelete();" value="Delete"/>

This is the javascript

<script type="text/javascript">
function confirmDelete()
{
    var status = confirm("Are you sure you want to delete ?");
    if(status)
    {
        parent.location.replace("parent.location='<?php echo "update.php";?>'");
    }else
    {
        parent.location.replace("parent.location='<?php echo "form.php?ticket=".$c['no'] ?>'");
    }
}
</script>

And this is the update.php

if(isset($_POST['update_button']))
{
    //update proses
}
else if(isset($_POST['delete_button']))
{
    //delete proses
}

I want delete confirmation show "Are you sure you want to delete ?" if I select "yes", it would delete from database and if I choose "Cancel", it will stay at current page (form.php).

Thanks before,

  • 写回答

2条回答 默认 最新

  • doucheng1944 2013-06-26 03:53
    关注

    You don't need to add javascript: in onclick or any event handling attribute. Just use onclick="return confirmDelete();"

    and your javascript will be like this:

    <script type="text/javascript">
      function confirmDelete() {
        var status  = confirm( "Are you sure you want to delete ?" );
        return status;
      }
    </script>
    

    alternately you can use onclick="return confirm( 'Are you sure you want to delete ?' );"

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

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效