Javascript自动表单提交不起作用
我有以下简单的HTML表单&我试图在页面加载期间自动提交表单。 下面的Javascript代码不会自动提交表单 HTML:Javascript自动表单提交不起作用,javascript,html,forms,Javascript,Html,Forms,我有以下简单的HTML表单&我试图在页面加载期间自动提交表单。 下面的Javascript代码不会自动提交表单 HTML: <form action="SSL.php" method="POST" name="TForm" id="transactionForm"> <input type="hidden" name="merchantTxnId" id="merchantTxnId" value="test"> <input type="submit" name=
<form action="SSL.php" method="POST" name="TForm" id="transactionForm">
<input type="hidden" name="merchantTxnId" id="merchantTxnId" value="test">
<input type="submit" name="submit" id="submit" value="submit" style="visibility:hidden">
</form>
Redirecting ... Please wait...
<script>
window.onload = function(){
alert(1); // this is working..
document.getElementById("transactionForm").submit(); //nothing is happening with this line . form is not getting submitted
}
</script>
重定向。。。请稍候。。。
Java脚本:
<form action="SSL.php" method="POST" name="TForm" id="transactionForm">
<input type="hidden" name="merchantTxnId" id="merchantTxnId" value="test">
<input type="submit" name="submit" id="submit" value="submit" style="visibility:hidden">
</form>
Redirecting ... Please wait...
<script>
window.onload = function(){
alert(1); // this is working..
document.getElementById("transactionForm").submit(); //nothing is happening with this line . form is not getting submitted
}
</script>
window.onload=函数(){
警报(1);//这正在工作。。
document.getElementById(“transactionForm”).submit();//此行未发生任何问题。未提交表单
}
我在Chrome控制台模式中发现以下错误:
请告诉我问题出在哪里…您不能使用
submit
作为任何表单元素的名称
或id
原因是,您可以通过document.getElementById('form')访问表单中的每个子项。其中name of child
是子项的name
。如果您有一个名为submit
,document.getElementById('form')。submit
是指向该子级的快捷方式
.submit()
的文档说明:
表单及其子元素不应使用
与表单属性(如提交、长度或方法)冲突。
名称冲突可能会导致混乱的失败
定义不工作
。是否在控制台中抛出错误?页面中发生了什么etc@VedantTerkar:其复制粘贴错误。我纠正了我的问题。你的警报是working@Nathan:在哪里可以看到JavaScript控制台?@logan在firefox中使用ctr+shift+k
,在chrome和IE 10+中使用F12
。对于console
@logan,如果您在Windows上使用Chrome,它是F12
,但是如果您在Mac上,它是Command+Shift+I
。那么解决方案是什么?@logan将输入的id和名称更改为其他内容。@logan答案是正确的。.submit()的文档说明表单及其子元素不应使用与表单属性(如submit、length或method)冲突的输入名称或ID。名称冲突可能会导致混乱的失败。”