Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- Accessing table cell data within list items with javascript


Piggo - 5:58 pm on Feb 9, 2012 (gmt 0)


I'm creating a list dynamically and I need to be able to retrieve values from the table cells. The structure is:

<ul id="tester">
<li><div><table><tr><td></td><td id="samecellid">I WANT THIS TD VALUE..
<li><div><table><tr><td></td><td id="samecellid">I WANT THIS TD VALUE..
<li><div><table><tr><td></td><td id="samecellid">I WANT THIS TD VALUE..

Each list item <li> has a table within it - this table only has one row, so the td id is unique within each list item but not within the list as a whole obviously.

The problem I have is I can't seem to get the value of the td cell. I have tried several ways, this is my latest and it doesn't work:

if (lengthoflist > 0) {
for (k=1; k<=lengthoflist; k++){

var ul = document.getElementById("tester");
var mya = ul.getElementsByTagName("li")[k];
var myb = mya.getElementsByTagName("div");
var myc = myb.getElementsByTagName("table");
var myd = myc.getElementsByTagName("tr");
var mye = myd.getElementById("samecellid");

var celldata = mye.innerHTML;
}
}

Thanks for any advice on this.


Thread source:: http://www.webmasterworld.com/javascript/4415992.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com