admin管理员组文章数量:1335371
Code
html
<form id="myFrm" name="myFrm" action="/myApp/ProcessFrm" method="post">
<input autofocus="autofocus" type="text" id="Location" name="Location" onkeydown="changetotab()" style="width: 4em" tabindex="1" />
<input type="Submit" value="Submit" id="submit" /> <br />
</form>
js
function changetotab() {
var charCode = (window.event.which) ? window.event.which : window.event.keyCode;
if (charCode == 13 || charCode == 9) {
if (document.myFrm.submit == undefined) {
alert("form submit can't be found")
} else {
alert("form can be submitted");
document.myFrm.submit();
}
}
}
What happens is that when the user pressed TAB or ENTER, document.myFrm.submit == undefined es up false (so far so good); then something weird happens - when I get to document.myFrm.submit(); JS informs that this method is not found.
0x80020003 - JavaScript runtime error: Member not found.
What is happening here?
Note: I can't use Jquery, just in case you were wondering why I am using old style JS. This will run on the old devices that do not support Jquery.
Code
html
<form id="myFrm" name="myFrm" action="/myApp/ProcessFrm" method="post">
<input autofocus="autofocus" type="text" id="Location" name="Location" onkeydown="changetotab()" style="width: 4em" tabindex="1" />
<input type="Submit" value="Submit" id="submit" /> <br />
</form>
js
function changetotab() {
var charCode = (window.event.which) ? window.event.which : window.event.keyCode;
if (charCode == 13 || charCode == 9) {
if (document.myFrm.submit == undefined) {
alert("form submit can't be found")
} else {
alert("form can be submitted");
document.myFrm.submit();
}
}
}
What happens is that when the user pressed TAB or ENTER, document.myFrm.submit == undefined es up false (so far so good); then something weird happens - when I get to document.myFrm.submit(); JS informs that this method is not found.
0x80020003 - JavaScript runtime error: Member not found.
What is happening here?
Note: I can't use Jquery, just in case you were wondering why I am using old style JS. This will run on the old devices that do not support Jquery.
Share Improve this question asked Apr 4, 2014 at 16:48 sarsnakesarsnake 27.7k62 gold badges185 silver badges294 bronze badges 13- did you try document.getElementById('myFrm') instead of document.myFrm? – Will N Commented Apr 4, 2014 at 16:52
- or document.forms["myFrm"] – Will N Commented Apr 4, 2014 at 16:53
- Just did try both - neither works. Trying not to rip my hair out. Let me reboot my Visual Studio. – sarsnake Commented Apr 4, 2014 at 16:55
- nope, no luck..... any ideas would be wele at this point – sarsnake Commented Apr 4, 2014 at 16:56
-
1
Before submitting do
alert(typeof document.myFrm.submit)
. What you see? – Teemu Commented Apr 4, 2014 at 16:57
2 Answers
Reset to default 10See this JSfiddle. What's going on here? Well, in the pre-DOM times, JavaScript created one property foo
for each input
with name foo
on the input
's parent form
:
form.foo.toString() === "HTMLInputElement";
This however, means, that, if you have an input element with name submit
, the form's own submit
method is overwritten. This behaviour has survived till today.
Now, your input has no name
attribute. In this case, the behaviour is to deduce one from the input
's ID, if one is set. So basically, change the ID of the input
, that's the most straight-forward way to deal with it:
<input type="Submit" value="Submit" id="submit_" />
There are lots of such subtleties, unfortunately. See DOMLint for a good overview.
Edit: What to do, if you end up with a clobbered submit
method and no way to change the HTML? Then fetch the submit method from the form's prototype and use that:
// form.submit() doesn't work, but this will:
HTMLFormElement.prototype.submit.call(form);
Try this (plain javascript):
document.getElementById('myFrm')
本文标签: Formsubmit is not found in JavascriptStack Overflow
版权声明:本文标题:Form.submit is not found in Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742257156a2441835.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论