Hi,
Below codes create 3 columns and 4 rows. Let’s just call Column A,B,C. C being the last column on the right (subtotal). The Total box sums up all the sub totals
I would like help on adding another code to the following logics:
-
the value put in Column A must always be multiplied by 5 and the product should appear in column C
example:
If value 5 is entered in Column A, the subtotal in column © should have 25. -
the value put in Column B must always be multiplied by 10 and the product should appear in the column C
example:
If value 3 is entered in Column B, the subtotal in column © should have 55 (result. from adding 25 and 30)
please help. Thank you in advance
+++++++++++++++++++++++++++++++++
<script type="text/javascript">
var howmanytoadd=2;
var rows;
onload = function()
{
rows=document.getElementById('table1').getElementsByTagName('tr');
var Numberofrows = document.getElementById("table1").rows.length
alert("found rows : " + Numberofrows)
for(var i=0;i<rows.length;i++)
{
alert (document.title = "Row : " + i + " Column : " + i)
for(var j=0;j<howmanytoadd;j++)
{
alert ("j :" + j)
rows[i].getElementsByTagName('input')[j].onkeyup=calc;
}
}
}
function calc()
{
var tot=0;
for(var i=0;i<rows.length;i++) // loop until hits the number of rows which is 4. so this will loop 4 times.
{
var linetot=0;
for(var j1=0;j1<howmanytoadd;j1++)
{
rows[i].getElementsByTagName('input')[howmanytoadd].value=linetot;
tot+=linetot;
}
document.getElementById('total').value =tot
} /*end of function CALC()*/
</script>
</head>
<body>
<form>
<table id="table1" width="600" border="0" cellspacing="1" cellpadding="1">
<tr id = "Row1">
<td style="width:80px"><input type="number" id="row1Col1"></td>
<td><input type="number" id="row1Col2"></td>
<td>=<input type="number" id="linetot1"></td>
</tr>
<tr id="Row2">
<td><input type="number">+</td>
<td><input type="number"></td>
<td>=<input type="number"></td>
</tr>
<tr id="Row3">
<td><input type="number">+</td>
<td><input type="number"></td>
<td>=<input type="number"></td>
</tr>
<!-- additional row -->
<tr id="Row4">
<td><input type="number">+</td>
<td><input type="number"></td>
<td>=<input type="number"></td>
</tr>
</table>
Total <input type="number" id="total">
</form>
</body>
</html>