Hello guys. I Found some code Dynamically Add/Remove Rows In HTML Table Using JavaScript and I found Here : http://viralpatel.net/blogs/dynamically-add-remove-rows-in-html-table-using-javascript/ then i copy and paste and run it in my browser . its successful ok. but when i Add A Little codes is not succesfful ok. because when i click add rows. no happen. i am not good in javascript. help me guys. thanks!
<HTML>
<HEAD>
<TITLE> Add/Remove dynamic rows in HTML table </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[i].innerHTML;
//alert(newcell.childNodes);
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;
break;
}
}
}
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[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
if(rowCount <= 1) {
alert("Cannot delete all the rows.");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}
}
}catch(e) {
alert(e);
}
}
</SCRIPT>
</HEAD>
<BODY>
<INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
<INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
<TABLE id="dataTable" class="rating" border="1">
<tr>
<th></th>
<th>CORE VALUES</th>
<th>BEHAVIORAL DESCRIPTION</th>
<th>PERCENTAGE</th>
</tr>
<TR>
<TD><INPUT type="checkbox" name="chk"/></TD>
<TD class="rating"><INPUT type="text" size="10" name="txt"/></TD>
<TD>
<textarea name="behavioral1" style="text-align:left;resize: none;" cols="85" rows="4" PlaceHolder="Add Description Here">