<html>
<head>
<TITLE>ROW Add</TITLE>
<script type="text/javascript">
function displayResult(j)
{
if (j <= document.getElementById("purchaseItems").rows.length) {
for (var i= document.getElementById("purchaseItems").rows.length; i>j ;i--) {
var elName = "addRow[" + i + "]";
var newName = "addRow[" + (i+1) + "]";
var newClick = "displayResult(" + (i+1) + ")";
var modEl = document.getElementsByName(elName);
modEl.setAttribute("onclick", newClick);
document.getElementsByName("addRow[" + i + "]").setAttribute('name', "addRow[" + (i+1) + "]");
}
}
var table=document.getElementById("purchaseItems");
var row=table.insertRow(j);
var cell1=row.insertCell(0);
var cell2=row.insertCell(1);
var cell3=row.insertCell(2);
var cell4=row.insertCell(3);
var cell5=row.insertCell(4);
cell1.innerHTML="<input type=text class='tbDescription' name='description[]' required/>";
cell2.innerHTML="<input type=text name='itemPrice[]' required />";
cell3.innerHTML="<input type=text name='itemquantity[]' required />";
cell4.innerHTML="<input type='text' name='lineTotal[]' readonly />";
cell5.innerHTML="<input type='button' name='addRow["+ j + "]' class='add' onclick=\"displayResult(" + (j+1) + ")\" value='+' />";
}
</script>
</head>
<body>
<h2>Add Row </h2>
<table id= "purchaseItems" name="purchaseItems" align="center">
<tr>
<th>Description</th>
<th>price</th>
<th>quantity</th>
<th>Line Total</th>
<td> </td>
</tr>
<tr>
<td><input type="text" name="description[]" class="tbDescription" required /></td>
<td><input type="text" name="price[]" required /></td>
<td><input type="text" name="quantity[]" required /></td>
<td><input type="text" name="lineTotal[]" readonly /></td>
<td><input type="button" name="addRow[1]" onclick="displayResult(2)" class="add" value='+' /></td>
</tr>
</table>
</body>
</html>
No comments:
Post a Comment