[英]Javascript form submits even when variable is false
So I am trying to have the user confirm their action before they submit the form, so I tried using the confirm box. 因此,我试图让用户在提交表单之前确认他们的操作,因此我尝试使用确认框。 When I tested it, even when I pressed Cancel in the confirm box the form submitted.
当我测试它时,即使在确认框中按“取消”时,也会提交表单。 So I tried just setting variable 'c' to false and then saying if c==true, submit the form, and the form still submitted!
因此,我尝试仅将变量'c'设置为false,然后说如果c == true,则提交表单,并且表单仍提交! I don't understand why this is happening.
我不明白为什么会这样。 Any help would be appreciated!
任何帮助,将不胜感激!
So just to be clear, the form still submits in the following code: 因此,为了清楚起见,该表单仍以以下代码提交:
<button onclick=\"extendBids('$studentID')\">Extend Bid</button>
<input type=\"radio\" name=\"extendBid\" id=\"$studentID 2\" value=\"$studentID\" style=\"visibility: hidden\"></input>
function extendBids(studentID) {
document.getElementById(studentID+" 2").checked=true;
//var c=confirm("Are you sure? This action cannot be undone.");
var c=false;
if (c==true){
document.forms["addToRush"].submit();
}
}
Try this - 尝试这个 -
<button onclick=\"extendBids('$studentID');\">Extend Bid</button>
<input type=\"radio\" name=\"extendBid\" id=\"$studentID 2\" value=\"$studentID\" style=\"visibility: hidden\"></input>
function extendBids(studentID) {
document.getElementById(studentID+" 2").checked=true;
if(confirm("Are you sure? This action cannot be undone.")){
document.forms["addToRush"].submit();
return true;
}
return false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.