Fiddling with tables

Discussion in 'JavaScript' started by James McMurray, Sep 29, 2007.

  1. #1
    I'm writing a page that includes a button whose function is to add a row to a table on the page. The bare bones of it is:

    
    	body = document.getElementsByTagName("body")[0];
    	tbl     = document.createElement("table");
    	tblBody = document.createElement("tbody");
    
    	row     = document.createElement("tr");
    	cell = document.createElement("td");
    	cellText = document.createTextNode("some text");
    	cell.appendChild(cellText);
    	cell.setAttribute("width", "3%");
    	row.appendChild(cell);
    
    	// repeat for a few more cells
    
    	// add the row to the end of the table body
    	tblBody.appendChild(row);
    	// put the <tbody> in the <table>
    	tbl.appendChild(tblBody);
    
    	body.appendChild(tbl);
    PHP:
    This works great except that when the page is saved, the document tree doesn't get saved, just the default blank table. So my question is twofold:

    1) Is there a way to save the document tree? or

    2) Is there a better way to append a row to a table on a page that will let you save the finished table when you're done?

    I can't create the table and fill it in with the button instead opf appending rows, because the button may be used multiple times so I don't know when I start how many rows I'll need.

    Thanks!
     
    James McMurray, Sep 29, 2007 IP
  2. mjamesb

    mjamesb Member

    Messages:
    88
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    48
    #2
    The only way to save the added rows would be by saving them on the server. You could use AJAX to send a message back to the server on the addrow function.
     
    mjamesb, Sep 30, 2007 IP
  3. James McMurray

    James McMurray Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Please forgive my unashamed ignorance, but what's Ajax?
     
    James McMurray, Oct 1, 2007 IP
  4. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #4
    blueparukia, Oct 1, 2007 IP
  5. James McMurray

    James McMurray Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks! I'll check it out ASAP.
     
    James McMurray, Oct 1, 2007 IP