Hello,
Here’s a simplified version of the function that’s giving me trouble:
[CODE]
function saveArray(w){
var arr=”[‘z’,[“;
var wc=w.childNodes; //get childNodes as array
for (n=0;n<wc.length;n++){ //for each of the childNodes
if (wc[n].type && wc[n].type==’checkbox’){ //if it’s a checkbox
if (arr!=”[‘z’,[“){arr+=”,”;} //add a comma to separate the arrays
arr+=”[‘a’,’b’,’c’,’d’]”; //add array
}else if (wc[n].tagName==’DIV’){ //if it’s a div
if (arr!=”[‘z’,[“){arr+=”,”;} //add a comma to separate the arrays
arr+=saveArray(wc[n]); //add array for div
}
}
arr+=”]]”;
return arr;
}
document.getElementById(‘test’).innerHTML=saveArray(<some div>);
If the structure looks something like this:
[CODE]
<DIV id=’a’>
<input type=’checkbox’ id=’cb_1′>
<input type=’checkbox’ id=’cb_2′>
<DIV id=’b’>
<input type=’checkbox’ id=’cb_3′>
<input type=’checkbox’ id=’cb_4′>
</DIV>
<input type=’checkbox’ id=’cb_5′>
<input type=’checkbox’ id=’cb_6′>
</DIV>
, the output string stops after cb_4 and does not finish the rest of the checkboxes.
The goal of what I’m trying to accomplish is take the given structure that’s on a page and transform the values i’m interested in into an array to store in a db or use later on. If anyone knows why this is or can think of a better way of doing this, I’m all ears!
Thanks for your suggestions.