Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript自动表单提交不起作用_Javascript_Html_Forms - Fatal编程技术网

Javascript自动表单提交不起作用

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=

我有以下简单的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="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。名称冲突可能会导致混乱的失败。”