admin管理员组文章数量:1191309
Question: How can you send a form with Javascript if one form input has the name submit
?
Background: I am redirecting the user to another page with a hidden HTML form. I cannot change name on the (hidden) inputs, since the other page is on another server and the inputs need to be exactly as they are. My HTML form looks like this:
<form id="redirectForm" method="post" action="/">
<input name="search" type="hidden" value="search for this" />
<input name="submit" type="hidden" value="search now" />
</form>
I use the following javascript line to send the form automatically today:
document.getElementById('redirectForm').submit();
However, since the name of one input is "submit" (it cannot be something else, or the other server won't handle the request), document.getElementById('redirectForm').submit
refers to the input as it overrides the form function submit()
.
The error message in Firefox is: Error: document.getElementById("requestform").submit is not a function
. Similar error message in Safari.
Question: How can you send a form with Javascript if one form input has the name submit
?
Background: I am redirecting the user to another page with a hidden HTML form. I cannot change name on the (hidden) inputs, since the other page is on another server and the inputs need to be exactly as they are. My HTML form looks like this:
<form id="redirectForm" method="post" action="http://www.example.com/">
<input name="search" type="hidden" value="search for this" />
<input name="submit" type="hidden" value="search now" />
</form>
I use the following javascript line to send the form automatically today:
document.getElementById('redirectForm').submit();
However, since the name of one input is "submit" (it cannot be something else, or the other server won't handle the request), document.getElementById('redirectForm').submit
refers to the input as it overrides the form function submit()
.
The error message in Firefox is: Error: document.getElementById("requestform").submit is not a function
. Similar error message in Safari.
2 Answers
Reset to default 17Worth noting: It's often a lot easier to just change the input name to something other than "submit". Please use the solution below only if that's really not possible.
You need to get the submit
function from a different form:
document.createElement('form').submit.call(document.getElementById('redirectForm'));
If you have already another <form>
tag, you can use it instead of creating another one.
Use submit()
method from HTMLFormElement.prototype
:
HTMLFormElement.prototype.submit.call(document.getElementById('redirectForm'));
本文标签: htmlHow send a form with Javascript when input name is quotsubmitquotStack Overflow
版权声明:本文标题:html - How send a form with Javascript when input name is "submit"? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738447114a2087277.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
document.getElementById('redirectForm').submit.click()
? :P – Stefan Commented Jan 4, 2012 at 15:32submit
does not have the type attributesubmit
orbutton
buthidden
. – AndersTornkvist Commented Jan 4, 2012 at 15:47