Using JavaScript in IE to invoke Form.submit () Prompt "Object does not support this property and method"

Source: Internet
Author: User

One of the magical questions that I stumbled into today in the project is hereby recorded.

First we look at the following code, the test page can look here, the function and logic of the page is very simple.

This code is logically free of errors and bugs that can theoretically be fully implemented.

    <body>
<script language= " JavaScript
Function Dosubmit ()
{
    var theform = document.getElementById (' theform ');
    theform.submit ();
}
</script>
    <form method= "POST" id= "Theform"
         <table width= ","
             <tr>
                 <td><input type= "text" value= "test" ></TD>
             </tr>
            < Tr>
                <td> <input type= "button" name= "Submit" value= "submitted" onclick= "DosUbmit () "></td>
            </tr>
        </table>
    </form>
</body>


If you use Firefox to view this page and click the Submit button, the form will be submitted normally, but we switch to ie below, IE will prompt "object does not support this property and methods" and stop the commit operation.

What the hell is going on here? After my many search data, found that the submit button Name= "Submit" properties in trouble.

At this time we will Theform.submit (), comment out, a new line of input alert (theform.submit.value), refresh the page and then click Submit Again, pop-up window will show "submit" two words, magic! Theform.submit is actually a submit button instead of a theform Method!

Why this problem occurs, because in IE can be through the form. Form element name This way you get all the form elements under a form, but here's how it happens. If the name of a form element is the same as the form's method name, then IE will first resolve the name to a FORM element. Instead of a form method, this is a magical problem.

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.