I’m having some issues with getting a parent nodes id to display in entirety.
I’m using a loop to detect div elements within a table, then I’m having it find the parent TD node and in another variable it gets the id off of that.
My problem is that during this loop im building a variable upon itself with this TD id inside an array and when it prints, the first time it will only show the first character, then the second time it will only show the 2nd character and any time after that will come up blank.
if i remove the array from the variable it will print the entire id, but it renames the old values to the most recent each time the loop runs.
Can someone help me figure this out?
Any help is appreciated, Thanks in advance.
Heres the function im writting
test.save = function () {
var cell = rd = REDIPS.drag,
page1a = document.getElementById(redips.p1a),
divs = TableID.getElementsByTagName('DIV'),
rd.find_parent('TD', rd.obj), //parent cell
st = cell.id, //parent cell ID
st,
id, //div id
cid, //cell id
ccid,
concatenator, // concatenate oDiv ID
query = '',
div, // current DIV element
i; // loop variable
for (i = 0; i < divs.length; i++) {
// set current DIV element
div = divs[i];
// set current TD ID
cid = st[i];
if (div.className.indexOf('drag') > -1) {
//takes two characters off of the DIV ID only
concatenator = div.id.substring(0, div.id.length - 2);
// creates the query through the loop
query += cid + '=' + concatenator + ' ';
}
}
if (query.length > 0) {
document.getElementById('message').innerHTML = query;
}
};
heres a link to a version using an array with the TD ID: http://stevenschemers.com/beta1/
and heres a link to a version not using an array for the TD ID: http://stevenschemers.com/beta2/
I also noticed, it seems like the loop if running twice, because ‘i’ will count up 0, 2, 4, 6. or sometimes 1, 3, 5, 7
1 Answer