[英]how to make document.forms[0].submit() work?
After i implemented my dialog box as a alert measure for user to confirm submission instead of a direct submission upon clicking, my document.forms[0].submit() does not work anymore. 在我将对话框实现为用户确认提交而不是单击后直接提交的警报措施之后,我的document.forms [0] .submit()不再起作用。 The page refreshes and the page stays the same.
页面刷新,并且页面保持不变。 Before that dialog box was created, everything works perfectly.
在创建该对话框之前,一切工作正常。 what is the problem here?
这里有什么问题?
After: 后:
<script>
//trigger dialog
$('#submitIter').click(function(){
$("#dialog-submit").dialog("open");
return false
});
$("#dialog-submit").dialog({
autoOpen: false,
resizable: false,
height: 200,
width: 200,
modal: true,
buttons: {
"Proceed": function(){
//submit after user clicks proceed cannot seem to work
document.forms[0].submit();
$(this).dialog("close");
}
}
});
</script>
<form action="{{ request.path }}" method="post" enctype="multipart/form-data">
<input type="image" src="images/submit.png" id="submitIter">
</form>
Before: 之前:
<script> document.forms[0].submit() </script>
I think you add some form before this one, try to write document.forms[1].submit(); 我认为您在此表单之前添加了一些表单,请尝试编写document.forms [1] .submit();。 Anyway as I can see you using jQuery, so you can write it this way:
无论如何,我可以使用jQuery看到您,因此可以这样编写:
<script>
//trigger dialog
$('#submitIter').click(function(){
$("#dialog-submit").dialog("open");
return false
});
$("#dialog-submit").dialog({
autoOpen: false,
resizable: false,
height: 200,
width: 200,
modal: true,
buttons: {
"Proceed": function(){
//submit after user clicks proceed cannot seem to work
$('#form_for_submit').submit();
$(this).dialog("close");
}
}
});
</script>
<form id="form_for_submit" action="{{ request.path }}" method="post" enctype="multipart/form-data">
<input type="image" src="images/submit.png" id="submitIter">
</form>
It may have something to do with scoping or potentially another form being added by the dialog. 它可能与作用域或对话框可能添加的其他表单有关。 My first debugging step would be to wrapp document.forms[0] into an alert and see if it returns an object.
我的第一个调试步骤是将document.forms [0]包装到警报中,看看它是否返回对象。 Secondly I would give the form tag an id to explicity reference it eg id="mainForm" then you can do
document.getElementById("mainForm").submit();
其次,我将给表单标签一个ID以明确引用它,例如id =“ mainForm”,然后您可以执行
document.getElementById("mainForm").submit();
Or you could write it as the other answer suggests 或者您也可以将其写为其他答案
$("#mainForm").submit();
Also try calling the dialog close command first. 另外,请尝试先调用对话框关闭命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.