<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> table page </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div style = "width: 500px">
<Table id = "alltable" border = "1px" cellpadding = "0px" cellspacing = "0px" width = "100%">
<Tr>
<TD> id </TD>
<TD> Delete </TD>
</Tr>
</Table>
<A href = "#" onclick = "addrow ();"> Add row </a> <br/>
<Input type = "text" id = "columnname"/> <a href = "#" onclick = "AddColumn ();"> Add column </a> <br/>
<Input type = "Submit" value = "Submit"/>
</Div>
</Form>
</Body>
</Html>
<SCRIPT type = "text/JScript">
Function AddColumn (){
VaR alltable = Document. getelementbyid ("alltable ");
VaR headerrow = alltable. Rows [0];
VaR newheadercol = headerrow. insertcell (headerrow. cells. Length-1 );
VaR headername = Document. getelementbyid ('columnname'). value;
VaR headerlable = Document. createelement ('label ');
Headerlable. innerhtml = headername;
Newheadercol. appendchild (headerlable );
Newheadercol. appendchild (document. createelement ('br '));
VaR A = Document. createelement ('A ');
A. href = '#';
A. onclick = function () {deletecolumn (newheadercol); Return false ;};
A. innerhtml = 'remove column ';
Newheadercol. appendchild ();
For (VAR I = 1; I <alltable. Rows. length; I ++ ){
VaR Col = alltable. Rows [I]. insertcell (alltable. Rows [I]. cells. Length-1 );
VaR TXT = Document. createelement ('input ');
TXT. type = 'text ';
TXT. value = I;
TXT. Name = 'txt '+ (I );
Col. appendchild (txt );
}
}
Function addrow (){
VaR alltable = Document. getelementbyid ("alltable ");
VaR lastrow = alltable. Rows [alltable. Rows. Length-1];
VaR ROW = alltable. insertrow (-1 );
For (VAR I = 0; I <lastrow. cells. length; I ++ ){
VaR Col = row. insertcell (-1 );
If (I! = Lastrow. cells. Length-1 ){
VaR TXT = Document. createelement ('input ');
TXT. type = 'text ';
TXT. value = lastrow. rowindex + 1;
TXT. Name = 'txt '+ (lastrow. rowindex + 1 );
Col. appendchild (txt );
} Else {
VaR BTN = Document. createelement ('input ');
BTN. type = 'click ';
BTN. value = "Delete row ";
BTN. Name = 'btndelete' + (lastrow. rowindex + 1 );
BTN. onclick = function () {deleterow (BTN); Return false ;};
Col. appendchild (BTN );
}
}
}
Function deleterow (BTN ){
VaR rownum = BTN. parentnode. parentnode. rowindex;
VaR alltable = Document. getelementbyid ("alltable ");
Alltable. deleterow (rownum );
}
Function deletecolumn (BTN ){
VaR alltable = Document. getelementbyid ("alltable ");
VaR Index = BTN. cellindex;
For (VAR I = 0; I <alltable. Rows. length; I ++ ){
Alltable. Rows [I]. deletecell (INDEX );
}
}
</SCRIPT>