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

N

NotGiven

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>
 

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,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top