Mozilla form elements problem

H

Howard Jess

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top