Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

html - JavaScript form submit WITH a field called submit

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...