In IE, when JavaScript is used to call form. submit (), the system prompts "the object does not support this attribute and method"

Source: Internet
Author: User

In IE, when JavaScript is used to call form. submit (), the system prompts "the object does not support this attribute and method"

This is a magical problem that we accidentally encountered in the project today.

First, let's take a look at the following code. The test page can be viewed here. The function and logic of the page are very simple.

Logically, this Code does not have any errors or bugs. In theory, it can be fully executed.

<Html>
<Head> IE test <Body>
<Script language = "javascript">
Function dosubmit ()
{
Var theform = document. getElementById ('theform ');
Theform. submit ();
}
</Script>
<Form method = "post" id = "theform">
& Lt; table width = "800" & gt;
<Tr>
<Td> <input type = "text" value = "test"> </td>
</Tr>
<Tr>
<Td> <input type = "button" name = "submit" value = "submit" onclick = "dosubmit ()"> </td>
</Tr>
</Table>
</Form>
</Body>
</Html>


If you use Firefox to view this page and click submit, the form will be submitted normally, but we switch to IE, IE will prompt "the object does not support this attribute and method" and stop submitting.

What's going on? After searching for information from multiple parties, I found that the attribute of the name = "submit" of the submit button was messy.

In this case, we set theform. submit (); comment out and input alert (theform. submit. value); refresh the page and click submit again. The pop-up window displays the word "Submit", which is amazing! Theform. submit is actually the submit button instead of the theform method!

Why does this problem occur, because the form can be used in IE. the form element name is used to obtain all the form elements in a form, if the name of a form element is the same as the method name of the form, IE will first resolve the name to a form element rather than the form method, this magic problem occurs now.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.