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>
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>