Click to See Complete Forum and Search --> : dynamic tables


punithkumar
12-08-2002, 11:31 AM
Hi,
I'm rookie in webdesigning..I have problem creating dynamic html tables.To be precise
I have to create a table initially with 4 rows after that if i want to add more rows i have to do it dynamically like i should have the option of a button r something so that when i click it a new row has to be added to the original table.
ur help is appreciated
thanks
punith

Ulukai
12-13-2002, 02:19 PM
Do something like this:

initially set up a div in html

<div id="myTable"></div>

in jscript you do something like this:

var myString = '<table>';
for(var i = 0; i < howmanyrowsyouwant; ++i){
myString += '<tr><td><div id="mycontent_row_'+i'"></div><\/td><\/tr>';
}
myString += '<\/table>';

var myObject = document.getElementById("myTable");
myObject.innerHTML = myString;

filling the content of the dynamically added rows and colums works exactly the same way. Setting the innerHTML of the object (e.g. mycontent_row_0) will do it.

NOTE: build the construct in a string and after building it, set innerHTML to the whole string. Donīt do by adding content to innerHTML. (Try it to see what happens)
Hope I could help you.

CU

Ulukai