Mozilla form elements problem

Discussion in 'Javascript' started by Howard Jess, Aug 31, 2004.

  1. Howard Jess

    Howard Jess Guest

    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
    Howard Jess, Aug 31, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henri
    Replies:
    9
    Views:
    1,811
    Toby Inkster
    Feb 22, 2005
  2. sama via DotNetMonster.com

    how to disable elements in div in mozilla

    sama via DotNetMonster.com, Sep 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    4,194
    S. Justin Gengo
    Sep 25, 2006
  3. Sergey Ilinsky
    Replies:
    1
    Views:
    142
    kaeli
    Jan 31, 2005
  4. Peter Wright
    Replies:
    2
    Views:
    134
    Peter Wright
    Mar 2, 2005
  5. Replies:
    4
    Views:
    178
Loading...

Share This Page