表单上的Java确认提交未取消 [英] Javascript Confirm on Form Submit Not Canceling

查看:72
本文介绍了表单上的Java确认提交未取消的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的Javascript函数,我想将其包含在表单中(提交或取消).问题是,如果我按取消",则应该取消表单提交.现在,它只是给我适当的警告,但无论我按下确定"还是取消",都继续提交表格.

I have a pretty simple Javascript function I want to include in a form (submit or cancel). The problem is it's supposed to cancel the form submit if I push cancel. Right now it just gives me the appropriate warning, but continues with submitting the form whether I push "ok" or "cancel".

我是JS的新手,如果我缺少一些基本知识,对不起,但是对于这个看似简单的问题,我似乎找不到一个可靠的答案.

I'm new to JS so sorry if I'm missing something basic, but I can't seem to find a solid answer to this seemingly simple problem.

JAVASCRIPT

JAVASCRIPT

function confirmdelete()
{
confirm("Deleting this answer may cause dataloss, are you sure you want to continue?")
}

PHP/HTML

echo '
    <form onsubmit="confirmdelete()" class="answerform" id="deletelink" action="/admin/questions" method="post"
    onsubmit="return confirm("Do you want to delete this answer?");>
        <input type="hidden" name="ansdel" value="' . $row['id'] . '">
        <input type="hidden" name="notice" value="You have deleted: ' . $row['answer'] . '">
        <input class="answerbutton" id="deletebutton" type="submit" value="Delete">
    </form>
';

推荐答案

通过放置

onsubmit="return confirmdelete()"

代替

onsubmit="confirmdelete()"

这是主要问题,还使用了Rob的一些更新作为最终的Javascript功能...谢谢!

That was the main issue, also used some of Rob's updates above for the final Javascript function... Thanks!

function confirmdelete() {
    var r=confirm("Deleting this answer may cause data loss, are you sure you want to continue?");
    if (r==true)
      {
        return true;
      }
    else
      {
        return false;
      }
}

这篇关于表单上的Java确认提交未取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆