Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. retreive table cell data

retreive table cell data

Scheduled Pinned Locked Moved JavaScript
tutorialjavascripttestingbeta-testinghelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MacRaider4
    wrote on last edited by
    #1

    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!!

    M G 2 Replies Last reply
    0
    • M MacRaider4

      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!!

      M Offline
      M Offline
      MacRaider4
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • M MacRaider4

        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!!

        G Offline
        G Offline
        Graham Breach
        wrote on last edited by
        #3

        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 with cell.getElementsByTagName('img'). W3schools has a decent reference and tutorial: http://www.w3schools.com/jsref/dom_obj_all.asp[^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups