dynamically add a cell into a tablerow

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anoopb81
    New Member
    • Nov 2006
    • 1

    dynamically add a cell into a tablerow

    how can I dynamicaly add cell into a row of HTML table using java script..
    Please help me..
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Hello Anoop, you can easily add a column into a table dynamically. The below coding will help you i think so

    [HTML]<html>
    <head>
    <script language="javas cript">
    function drawTableD(plac e) {
    if (document.creat eElement) {
    var oTable = document.create Element('table' );
    oTable.style.bo rder = '1px solid red';
    var oTbody = document.create Element('tbody' );
    var oRow = document.create Element('tr');

    // Put 4 cells in the a row
    for (var i=0; i<4; i++) {
    var oCell = document.create Element('td');
    var oTxt = document.create TextNode('a cell');
    oCell.style.bor der = '1px solid blue';
    oCell.appendChi ld(oTxt);
    oRow.appendChil d(oCell);
    }

    oTbody.appendCh ild(oRow);
    oTable.appendCh ild(oTbody);
    place.appendChi ld(oTable);
    }
    }
    </script>
    </head><body>
    <div>
    <button onclick="drawTa bleD(this.paren tNode);">Draw Table (DOM)</button>
    </div>
    </body>
    </html>[/HTML]

    If any more doubts means please post your queries

    Regards
    Ramanan Kalirajan

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5390

      #3
      changed thread title ... please be sure to use a proper thread title for your post ... read this section of the posting guidelines ...

      kind regards
      MOD

      Comment

      • RamananKalirajan
        Contributor
        • Mar 2008
        • 608

        #4
        Originally posted by gits
        changed thread title ... please be sure to use a proper thread title for your post ... read this section of the posting guidelines ...

        kind regards
        MOD
        I am extremely sorry Mr. Gits, I had entered mistakenly entered how to create column dynamically in a table, but the thing is I had given the code which first creates a row dynamically and append the column to it.

        I apologize for my mistake I am really sorry

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5390

          #5
          Originally posted by RamananKaliraja n
          I am extremely sorry Mr. Gits, I had entered mistakenly entered how to create column dynamically in a table, but the thing is I had given the code which first creates a row dynamically and append the column to it.

          I apologize for my mistake I am really sorry
          no need to apologize for :) ... i just saw that was what the OP wanted ... but i think he/she should provide more information since we should know whether it is an existing table or a new one ... so that we would have to deal with some colspan etc.?

          kind regards

          Comment

          Working...