My function calc() is not working !!
Here I want to multiply the data in the field Price and Amount and put it in field sum.
It works for first row when I use getElementsById, but when I add new row this don't work for the new row data.
Please tell me if I can do it with getElementsByName or getElementsById ??
function addRow(billingTable)
{
var table = document.getElementById(billingTable);
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[1].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;
}
}
}
function deleteRow(billingTable)
{
try {
var table = document.getElementById(billingTable);
var rowCount = table.rows.length - 1;
for (var i = 1; i <= rowCount; i++)
{
var row = table.rows[i];
var chkbox = row.cells[0].children[0];
if (null != chkbox && true == chkbox.checked)
{
if (rowCount <= 1)
{
alert("Alle zeilen kann nicht gelöscht werden.");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}
}
} catch(e)
{
alert(e);
}
}
function calc()
{
var amount = document.c("Amount")[0];
alert(amount);
var price = document.getElementsByName("Price");
document.getElementsByName('Sum') . value = amount*price;
}
<table border="1" id="billingTable">
<tr>
<th></th>
<th>Position</th>
<th>Amount</th>
<th>Price</th>
<th>Sum</th>
</tr>
<tr>
<td>
<INPUT type="checkbox" name="chk"/>
</td>
<td>
<input type="text" name="Position" style="width: 140px"/>
</td>
<td>
<input type="text" id="Amount_1" name="Amount" style="width: 140px"/>
</td>
<td>
<input type="text" id="Price_1" name="Price" style="width: 139px" onchange="calc()"/>
</td>
<td>
<input type="text" id="Sum_1" name="Sum" style="width: 139px"/>
</td>
</tr>
</table>