sajan Posted January 25, 2008 Share Posted January 25, 2008 Hi how should dynamically add rows to a table.The data is from php output through ajax.Suppose I have a table called <table id="table1"></table> .How can i add dynamic values to the table. Link to comment Share on other sites More sharing options...
Ingolme Posted January 25, 2008 Share Posted January 25, 2008 That depends on what the data obtained from the PHP file looks like.There's not one single way. Link to comment Share on other sites More sharing options...
jeffman Posted January 25, 2008 Share Posted January 25, 2008 This lesson might help, and if the associated Tryit Editior is working (sigh) you can get a really good sense of what the methods really do.http://www.w3schools.com/htmldom/met_table_insertrow.asp Link to comment Share on other sites More sharing options...
sajan Posted January 28, 2008 Author Share Posted January 28, 2008 The data is some descriptions and names.I want to add these to table .And next time i call a different set i have to delete the entire row and add new rows.Any suggestion? Link to comment Share on other sites More sharing options...
justsomeguy Posted January 28, 2008 Share Posted January 28, 2008 Here's a function that removes all children, you can call this function on the table to remove all of the rows in it: function removeChildren(el){ for (var i = el.childNodes.length - 1; i >= 0; i--) el.removeChild(el.childNodes[i]);} As far as building a set of rows, look at the DOM reference on the w3schools site. The functions you will need to use are the document.getElementById function to get a reference to the table, and then the document.createElement function to create the table elements (tbody, tr, td, etc), then the element.appendChild function to add the new elements to the table and maybe document.createTextNode when you want to put text in the cells in the table. There's also a good DOM reference here:http://www.howtocreate.co.uk/tutorials/jav...pt/domstructure Link to comment Share on other sites More sharing options...
sajan Posted January 30, 2008 Author Share Posted January 30, 2008 Thanks, that link is useful.The delete function worked well in firefox,but in explorer if we delete then dynamically create then delete,if these process repeat few times ,IE crashes. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 30, 2008 Share Posted January 30, 2008 There might be a memory leak somewhere. Watch the memory that IE is using when you're doing that. If it keeps going up then there's a leak in your code. Theoretically, if you add a bunch of elements and check the memory, then delete all those elements, then add them back again, IE should be using approximately the same amount of memory. Link to comment Share on other sites More sharing options...
sajan Posted January 31, 2008 Author Share Posted January 31, 2008 How do i check memmory leak in ie? Link to comment Share on other sites More sharing options...
justsomeguy Posted January 31, 2008 Share Posted January 31, 2008 Open task manager using CTRL-SHIFT-ESC. Click the Processes tab. Go to View -> Select Columns. Make sure Memory Usage, Peak Memory Usage, and Virtual Memory Size are all selected. Watch the memory usage column for iexplore.exe when you're testing. It will be best to not have any other pages open while testing, shut down IE then start it back up again and run your test. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.