get a table cell value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yukatan

    get a table cell value

    let's say this is a html table, how can i get the string value contained in
    the X cell ?

    ---------------------
    | | | |
    ---------------------
    | | | |
    ---------------------
    | X | | |
    ---------------------
    | | | |
    ---------------------

    thanks


  • Lasse Reichstein Nielsen

    #2
    Re: get a table cell value

    "yukatan" <a@a.com> writes:
    [color=blue]
    > let's say this is a html table, how can i get the string value contained in
    > the X cell ?[/color]

    Don't draw using a proportional font. There is little chance that the
    receiver uses the same proportional font. If you draw using a fixed
    width font, then at least all other fixed width fonts will give a
    correct drawing. My newsreader uses a fixed with font, as does a lot
    of others.

    [color=blue]
    > ---------------------
    > | | | |
    > ---------------------
    > | | | |
    > ---------------------
    > | X | | |
    > ---------------------
    > | | | |
    > ---------------------[/color]

    To get the cell, assuming that the id of the table is "tableId":

    var table = document.getEle mentById("table Id");
    var row = table.rows[2];
    var cell = row.cells[0];

    The hard part is getting the content of the cell. If it is plain,
    unstyled text, then you can probably use:

    var content = cell.firstChild .nodeValue;

    Otherwise you must either use proprietary methods like cell.innerText
    that doesn't work in all modern browsers, or you must gather the text
    recursively. Since you just say "string value", I assume it is plain,
    unstyled text.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • HikksNotAtHome

      #3
      Re: get a table cell value

      In article <llqtb41v.fsf@h otpop.com>, Lasse Reichstein Nielsen <lrn@hotpop.com >
      writes:
      [color=blue]
      >Otherwise you must either use proprietary methods like cell.innerText
      >that doesn't work in all modern browsers, or you must gather the text
      >recursively. Since you just say "string value", I assume it is plain,
      >unstyled text.[/color]

      Whether its styled text or not, why not innerHTML if you get out of the W3C and
      into proprietary? At least allows it to work somewhere besides IE :(
      --
      Randy

      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: get a table cell value

        hikksnotathome@ aol.com (HikksNotAtHome ) writes:
        [color=blue]
        > Whether its styled text or not, why not innerHTML if you get out of
        > the W3C and into proprietary? At least allows it to work somewhere
        > besides IE :([/color]

        Yes, but that doesn't get the text of styled content, but the HTML code.
        You will have to remove the tags to get just the text.

        It all depends on what the original poster wants, which wasn't clear.

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        Working...