retreive table cell data
-
Ok I'm trying to figure out how to loop through the values of my table cells (they all have a image in them). When I created the cells I named them with a id="A2" (for example). the code I've been trying in testing looks like this:
savedSquares = document.getElementById('A2');
alert("a2 = " + savedSquares);
alert(document.getElementById("innerSquares").rows[0].cells.length);
//alert(document.images('a2').src);
address = document.getElementById("innerSquares").rows[0].cells[3].value;
alert("cell = " + address);The results in order are A2 = [object HTMLTableCellElement] 10 (this is correct) cell = undefined I've tried a bunch of other combos but this is what I currently have. The images are also named the same so the image in "A2" is also named the same way:
<img src="images/o.jpg" border="0" height="100" width="100" name="A2" alt="Open">
Not sure if that will make it easier but I haven't been able to read those with my limited knowledge of JavaScript. The looping through part won't be a issue, I just need to figure out how to get the name of the image or even the alt text would be doable. Thanks in advance!!
-
Ok I'm trying to figure out how to loop through the values of my table cells (they all have a image in them). When I created the cells I named them with a id="A2" (for example). the code I've been trying in testing looks like this:
savedSquares = document.getElementById('A2');
alert("a2 = " + savedSquares);
alert(document.getElementById("innerSquares").rows[0].cells.length);
//alert(document.images('a2').src);
address = document.getElementById("innerSquares").rows[0].cells[3].value;
alert("cell = " + address);The results in order are A2 = [object HTMLTableCellElement] 10 (this is correct) cell = undefined I've tried a bunch of other combos but this is what I currently have. The images are also named the same so the image in "A2" is also named the same way:
<img src="images/o.jpg" border="0" height="100" width="100" name="A2" alt="Open">
Not sure if that will make it easier but I haven't been able to read those with my limited knowledge of JavaScript. The looping through part won't be a issue, I just need to figure out how to get the name of the image or even the alt text would be doable. Thanks in advance!!
Ok so I made some progress... if I use
savedSquares = document.images['A2'].alt;
it retreives the alt value which is a step in the right direction. Just wondering if there is a better way?
-
Ok I'm trying to figure out how to loop through the values of my table cells (they all have a image in them). When I created the cells I named them with a id="A2" (for example). the code I've been trying in testing looks like this:
savedSquares = document.getElementById('A2');
alert("a2 = " + savedSquares);
alert(document.getElementById("innerSquares").rows[0].cells.length);
//alert(document.images('a2').src);
address = document.getElementById("innerSquares").rows[0].cells[3].value;
alert("cell = " + address);The results in order are A2 = [object HTMLTableCellElement] 10 (this is correct) cell = undefined I've tried a bunch of other combos but this is what I currently have. The images are also named the same so the image in "A2" is also named the same way:
<img src="images/o.jpg" border="0" height="100" width="100" name="A2" alt="Open">
Not sure if that will make it easier but I haven't been able to read those with my limited knowledge of JavaScript. The looping through part won't be a issue, I just need to figure out how to get the name of the image or even the alt text would be doable. Thanks in advance!!
It's not very clear to me what you are trying to do. Table cells don't have values, they are just container elements. If you have a table cell, you can loop through its contents using
cell.childNodes
(where 'cell' is your cell element). Or you could get a list of all the images contained in the cell withcell.getElementsByTagName('img')
. W3schools has a decent reference and tutorial: http://www.w3schools.com/jsref/dom_obj_all.asp[^]