Firefox doesn't like appendChild()

Discussion in 'Javascript' started by Christina, Nov 19, 2006.

  1. Christina

    Christina Guest

    I have 2 list boxes - one to fill the second one based on the selection, or
    move all items. You can remove the selection (or all items) from the second
    one to place it back in the first one. I expanded my horizons and thought
    to use script based on the js node operation appendChild(). It seemed so
    clean and easy to follow. Works beautifully in IE, but Firefox sees the
    value for a nanosecond but doesn't put it in the box. This is the relevant
    js:

    function addSide(){
    var addIndex = document.forms[0].sides.selectedIndex;

    if (addIndex >= 0)
    {
    document.forms[0].selectedSides.appendChild(document.forms[0].sides.options(addIndex));
    }

    }

    function delSide(){
    var selIndex = document.forms[0].selectedSides.selectedIndex;
    if (selIndex >= 0)
    {
    document.forms[0].sides.appendChild(document.forms[0].selectedSides.options(selIndex))
    }

    }

    function addAll(){
    var len = document.forms[0].sides.length -1;
    for(i=len; i>=0; i--){
    document.forms[0].selectedSides.appendChild(document.forms[0].sides(i));
    }

    }

    function delAll(){
    var len = document.forms[0].selectedSides.length -1;
    for(i=len; i>=0; i--){
    document.forms[0].sides.appendChild(document.forms[0].selectedSides(i));
    }

    }



    Is there a way to make it work for FF, or do I need to just start over and
    not use appendChild()? Is there a better way?

    Thanks,

    Christina
    Christina, Nov 19, 2006
    #1
    1. Advertising

  2. Christina

    RobG Guest

    Christina wrote:
    > I have 2 list boxes - one to fill the second one based on the selection, or
    > move all items. You can remove the selection (or all items) from the second
    > one to place it back in the first one. I expanded my horizons and thought
    > to use script based on the js node operation appendChild(). It seemed so
    > clean and easy to follow. Works beautifully in IE, but Firefox sees the
    > value for a nanosecond but doesn't put it in the box.


    Did you get an error message in the error console? Get the Firebug
    extension and you will won't miss them.

    <URL: https://addons.mozilla.org/firefox/1843/ >



    > This is the relevant
    > js:
    >
    > function addSide(){
    > var addIndex = document.forms[0].sides.selectedIndex;
    >
    > if (addIndex >= 0)
    > {
    > document.forms[0].selectedSides.appendChild(document.forms[0].sides.options(addIndex));


    This should produce an error message something like:

    "document.forms[0].sides.options is not a function"


    The options object is a collection, you want to refer to its members by
    index using square bracket notation:

    ...appendChild( document.forms[0].sides.options[addIndex] );

    and so on for the rest of your script.


    --
    Rob
    RobG, Nov 19, 2006
    #2
    1. Advertising

  3. Christina

    Christina Guest

    Hi Rob,

    Perfect. I knew it had to be something simple - wonder why the original
    code used parens rather than brackets? Good ol' IE - it'll accept anything
    :) Thanks for the link - I haven't used FF much but need to start because
    I've seen that it has what appear to be good extensions. Never used IE until
    3 years ago - always used Netscape - but my college required IE for online
    classes and got in the habit.

    Thanks a bunch,
    Christina

    "RobG" <> wrote in message
    news:...
    >
    > The options object is a collection, you want to refer to its members by
    > index using square bracket notation:
    >
    > ...appendChild( document.forms[0].sides.options[addIndex] );
    >
    > and so on for the rest of your script.
    >
    >
    > --
    > Rob
    >
    Christina, Nov 19, 2006
    #3
    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. =?Utf-8?B?YmVhbndlZWQ=?=

    AppendChild removes like nodes?

    =?Utf-8?B?YmVhbndlZWQ=?=, Mar 1, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    344
    bruce barker
    Mar 1, 2005
  2. David Henderson
    Replies:
    3
    Views:
    3,240
    Jerinaw
    Dec 30, 2010
  3. Stewart
    Replies:
    7
    Views:
    129
    Stewart
    Aug 25, 2005
  4. Derek Basch
    Replies:
    1
    Views:
    128
  5. Derek Basch
    Replies:
    0
    Views:
    157
    Derek Basch
    May 24, 2007
Loading...

Share This Page