Click here to Skip to main content
15,908,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<script>
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>

<table class="Grid" border="1" cellpadding="0" cellspacing="0" style="border-bottom:0px;">
<tbody id="selEmp">
<tr class="Caption">
<th>Sel</th>
<th width="46%">PROJECT NAME</th>
<th width="14%">NUMBER OF<br>YEARS</th>
<th width="14%">SCOPE OF<br>WORKS VALUES</th>
<th width="14%">SITE CONDITION<br>VALUES</th> <th >TOTAL PER<br>PROJECT</th>
<th><INPUT class="buttonClass" type="button" value="Add" onClick="addRow('dataTable')" />&nbsp;&nbsp;</th>
<th><INPUT class="buttonClass" type="button" value="Del" onClick="deleteRow('dataTable')" /></th>
</tr>
<tbody id="dataTable">
<tr>
<TD><INPUT type="checkbox" name="chk" width="2%"/></TD>
<td style='width:45%;' align="center">
<select name="Check" id="Check">
<option value="1">Java</option>
<option value="2">PHP</option>
<option value="3">Java Script</option>
<option value="4">PERL</option>
<option value="5">ASP</option>
<option value="6">ASP .net</option>
<option value="7">Java Server Pages</option>
<option value="8">EJB</option>
<option value="9">FORTRAN</option>
<option value="10">COBOL</option>
</select>
</td>
<TD align="center"><INPUT type="text" size="6" name="no_years" value="0"/></TD>
<TD align="center"><INPUT type="text" size="6" name="works_val" value="0"/></TD>
<TD align="center"><INPUT type="text" size="6" name="site_cond" value="0"/></TD>
<TD align="center"><INPUT type="text" size="6" name="tot_prj" value="0"/></TD>
</tr>

</tbody>

</tbody>
</table>
Posted

1 solution

Now the Issue is if i add the more rows and then run a loop to the till the count of child numbers appended i can only get the value of the first row..kindly can someone make the modification whatsoever required.. That shall be highly appreciated..
Regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900