createElement name not setting in...?
Posted: Wed Sep 16, 2009 10:27 pm
Hey I'm trying to get a bit of Ajax working, and I'm stuck on the very last part. Here's the chunk of code:
I'm sure there are better ways to do this, but this is how I've got it to work. If I put a tr element in the page, outside of the code, with the name 'basketRow', it is recognized by that piece of code and is removed when this script runs. However, the dynamically created and added rows are not. I'm guessing this is because I'm not applying the name properly, but I'm not sure. Any help would be greatly appreciated.
Code: Select all
var receivedText = theSync.responseText; //data as a string
if(receivedText .indexOf('%tr' != -1))
{
//remove old entries
//alert(document.getElementsByName("basketRow").length); - outputs 0, suggesting my theTR.name is not working...
for(l = 0; l < document.getElementsByName("basketRow").length; l++)
{
document.getElementsByName("basketRow")[l].parentNode.removeChild(document.getElementsByName("basketRow")[l]);
}
//go through each tr
element = receivedText.split('%tr');
for(i = 0; i < element.length; i++)
{
var theTR = document.createElement("tr");
theTR.name = "basketRow"; //I believe this is the offender...
if(element[i] .indexOf('%td' != -1))
{
pieces = element[i].split('%td');
//go through each td
for(j = 0; j < pieces.length; j++)
{
var theTD = document.createElement("td");
theTD.innerHTML = pieces[j];
theTD.vAlign = "top";
theTR.appendChild(theTD);
}
//output row
document.getElementById("basketShort").parentNode.insertBefore(theTR, document.getElementById("basketShort"));
}
}
}