<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<SCRIPT language="javascript">
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount =table.rows[0].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells.innerHTML ;
//alert(newcell.childNodes);
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
}
}
if(table.rows.length>=10){
document.getElementById('addrw1').style.visibility='hidden';
}
}
function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows;
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
if(rowCount <= 1) {
alert("Cannot be delete ");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}
}
}catch(e) {
alert(e);
}
}
function add5row(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount =table.rows[0].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells.innerHTML ;
//alert(newcell.childNodes);
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
}
}
if(table.rows.length>=10){
document.getElementById('addrw1').style.visibility='hidden';
}
}
</SCRIPT>
</head>
<body>
<div id="fields" style="background:#036;">
<TABLE id="dataTable" width="600px" border="1">
<TR>
<TD><INPUT type="checkbox" name="chk"/></TD>
<TD>NAME: <INPUT type="text" name="txt"/></TD>
<TD>E-MAIL: <input type="text" name="txt"/></TD>
</TR>
<TR>
<TD><INPUT type="checkbox" name="chk"/></TD>
<TD>NAME: <INPUT type="text" name="txt"/></TD>
<TD>E-MAIL: <input type="text" name="txt"/></TD>
</TR>
<TR>
<TD><INPUT type="checkbox" name="chk"/></TD>
<TD>NAME: <INPUT type="text" name="txt"/></TD>
<TD>E-MAIL: <input type="text" name="txt"/></TD>
</TR>
<TR>
<TD><INPUT type="checkbox" name="chk"/></TD>
<TD>NAME: <INPUT type="text" name="txt"/></TD>
<TD>E-MAIL: <input type="text" name="txt"/></TD>
</TR>
<TR>
<TD><INPUT type="checkbox" name="chk"/></TD>
<TD>NAME: <INPUT type="text" name="txt"/></TD>
<TD>E-MAIL: <input type="text" name="txt"/></TD>
</TR>
</TABLE></div>
<INPUT name="addrw1" type="button" id="addrw1" onclick="addRow('dataTable')" value="Add Row" />
<INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
<input type="button" name="button" id="button" value="Add 5more" onclick="add5row('dataTable')"/>
</body>
</html>
Hey can any one please let me know how to add 5 rows dynamically by clicking on add5rows button