Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Mozilla form elements problem

Reply
Thread Tools

Mozilla form elements problem

 
 
Howard Jess
Guest
Posts: n/a
 
      08-31-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newb: recurse over elements children and disable all form elements SteveKlett@gmail.com Javascript 4 09-20-2006 07:42 AM
struts indexed form elements not getting into form bean apaeth@fortdearborn.com Java 1 01-07-2006 09:29 PM
Form images don't appear in form.elements Howard Jess Javascript 1 10-18-2004 07:15 PM
Does form.disable work on hidden text form elements? Mark Hannon Javascript 3 09-02-2004 11:37 PM
File uploading from a form with textbox form elements Andy Johns ASP .Net 2 03-02-2004 06:21 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57