HTML Form Issue

Source: Internet
Author: User

The form is designed to support direct access to control via name, as a result of compatible DOM0 relationships. For example, if you have a <input name= "user"/> You can use a form such as document.forms[0]["user" directly, or you can directly document.forms[0].user without special characters.

However, this raises the question of what happens to name if it conflicts with a method or property on a form (for example, a form has a length property and a control that adds a name of length to the form).

After my test, in IE (XP 6.0) and Firefox (1.5), name will overwrite the original property or method. Which is priority forward compatibility.

As a trade-off, this practice has no certainty. But the problem is that, in scripting, name and method conflict can create strange behavior that developer unexpected. And it's not recorded in any of the documents I see. (Perhaps I am ignorant, there are ways to avoid it?) Especially in IE, for element and some built-in methods of ToString () incredibly irresponsible return "[object]", once the problem, completely confusing.

For example, I happen to have a script that detects whether a form contains control for a particular name, and IE's form has an extra Item method, and the result is that I have to deal with it specifically:

control = Myform[name];
if (typeof control = = "Undefined" | |
(Name = = "Item" && control = = "[Object]")
...

Of course, I should actually do a special test for all of the form's properties and methods.

Obviously, in order for the script to work correctly, no mask of name should be allowed (think of the case as action, method, submit, reset, etc.). However, it is not realistic for web designers to remember a whole bunch of names that should be reserved for form scripting.

So the conclusion is that this forward compatibility is the wrong design decision.

Note: Submit it as a bug to Mozilla. I do not know what will be the response.



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.