code "insertHere.parentNode.insertBefore(newfields,insertHere);" over-writing itself

Discussion in 'XML' started by NotGiven, Sep 17, 2004.

  1. NotGiven

    NotGiven Guest

    The code below is overwriting istself. I think it might be that I have to
    appedn it to the dom each loop.

    What it is doing is creating the fiels correctly the first time through.
    Then it over writes those same field again and again. I can tell because the
    value of the first field changes every loop.

    Any ideas?



    Code:


    var ex_counter = 0;
    var ex = "";
    function ex_morefields() {
    var x=document.getElementById("choices");
    ex_counter++;
    var newfields = document.getElementById('ex_fields').cloneNode(true);
    newfields.id = '';
    newfields.style.display = 'block';
    var newfield = newfields.childNodes;
    for (y = 0; y<(x.length); y++) { //loop through all item in the list
    ex = x[y].text;
    for (var i=0;i<newfield.length;i++) {
    var theName = newfield.name;
    if (theName) {
    newfield.name = theName;// + ex_counter;
    }
    if (theName == "exercise") {
    newfield.setAttribute('value', ex);
    }
    }
    var insertHere = document.getElementById('write_EX');
    insertHere.parentNode.insertBefore(newfields,insertHere);
    }
    } // end add more software script
    here's the html in the page:

    HTML:


    <span id="write_EX"></span>
     
    NotGiven, Sep 17, 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. Mike
    Replies:
    4
    Views:
    490
    Roedy Green
    Aug 26, 2005
  2. Replies:
    5
    Views:
    415
    Cedric LEMAIRE
    Sep 3, 2003
  3. Dominik Kaspar

    writing code over several lines

    Dominik Kaspar, Oct 17, 2003, in forum: Python
    Replies:
    20
    Views:
    609
    Peter Hansen
    Oct 21, 2003
  4. mr_cross
    Replies:
    11
    Views:
    619
    dorayme
    Oct 11, 2006
  5. NotGiven
    Replies:
    0
    Views:
    95
    NotGiven
    Sep 16, 2004
Loading...

Share This Page