Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   Mozilla form elements problem (http://www.velocityreviews.com/forums/t879212-mozilla-form-elements-problem.html)

Howard Jess 08-31-2004 12:22 AM

Mozilla form elements problem
 
The following piece of code yields different results in Mozilla and IE:

f = document.createElement('form');
ip1 = document.createElement('input'); ip1.type = 'text';
f.appendChild(ip1);
alert("1. Elements length=" + f.elements.length);
document.body.appendChild(f);
alert("2. Elements length=" + f.elements.length);
ip2 = document.createElement('input'); ip2.type = 'text';
f.appendChild(ip2);
alert("3. Elements length=" + f.elements.length);
document.body.removeChild(f);
alert("4. Elements length=" + f.elements.length);
f.removeChild(ip1);
alert("5. Elements length=" + f.elements.length);

In IE (and Opera), the alerts read:

1. Elements length=1
2. Elements length=1
3. Elements length=2
4. Elements length=2
5. Elements length=1

In Mozilla, they read:

1. Elements length=0
2. Elements length=1
3. Elements length=2
4. Elements length=2
5. Elements length=1

Apparently, Mozilla doesn't update a form's elements collection as
elements are added to the form, unless the form is part of the document.
However, it *does* update the collection as elements are removed from
the form, whether or not the form is part of the document.

This is inconsistent, but is it a bug? I don't see this reading Bugzilla,
but I'm not sure how to search there for information.

Help, anyone?

hj


All times are GMT. The time now is 10:28 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.