JavaScript form submit WITH a field called submit

浪子不回头ぞ 提交于 2019-12-17 10:05:51

问题


I was wondering if there is any method (using JS or otherwise) to autosubmit a form with a field with name and id as 'submit'. Essentially, my entire HTML code looks like this:

<html>
<body onload=myForm.submit()>
<form id="myForm" name="myForm" action="http://example.com/examplePage.do" method="POST">
<input type=hidden name="val1" id="val1" value="some_Value"/>
<input type=hidden name="val2" id="val2" value="another_Value"/>
<input type=hidden name="val3" id="val3" value="yet_another_Value"/>
<input type=hidden name="submit" id="submit" value="Continue"/>
</form>
</body>
</html>

Obviously, the myForm.submit() returns a myForm.submit is not a function error. The server rejects the request if there is no 'submit' field with value as 'Continue' and the requirement is to auto-submit this.


回答1:


The submit function for that form is completely inaccessible (it has been overwritten). You can steal one from another form though.

document.createElement('form').submit.call(document.getElementById('myform'))

Doesn't work in old-IE. (I think support appears from IE7 onwards)



来源:https://stackoverflow.com/questions/18937990/javascript-form-submit-with-a-field-called-submit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!