Hi everyone..I have a problem..
I want to make an auto calculation on each row..the things is, I only can do it on the first row..but for the second row, nothing happened..
here is my code:
<script>
function compute() {
var inputObj = document.getElementById('k8goodsQty');
var otherObj = document.getElementById('valuePerUnit');
var diffObj = document.getElementById('valueTotal');
var v1=inputObj.value;
var v2=otherObj.value;
var val1 = v1==="" ? 0 : parseFloat(v1); // convert string to float
var val2 = v2==="" ? 0 : parseFloat(v2);
diffObj.value = val1 * val2;
}
</script>
and here is my table:
<?php
$defaultrow = 3;
?>
<table>
<thead>
<th>No</th>
<th>Goods<span class="red">*</span></th>
<th>Quantity<span class="red">*</span></th>
<th>Value per unit<span class="red">*</span></th>
<th>Total<span class="red">*</span></th>
</thead>
<?php for ( $i=1; $i<=$defaultrow; $i++ ) { ?>
<tr>
<td class="labelcell"><?php echo $i; ?></td>
<td class="datacell"><input type="text" id="goodsDesc" name="goodsDesc[<?php echo $i; ?>]" maxlength="200" /></td>
<td class="datacell"><input type="text" id="k8goodsQty" name="k8goodsQty[<?php echo $i; ?>]" maxlength="200" onKeyUp="compute()"/></td>
<td class="datacell"><input type="text" id="valuePerUnit" name="valuePerUnit[<?php echo $i; ?>]" maxlength="200" onKeyUp="compute()"/></td>
<td class="datacell"><input type="text" id="valueTotal" name="valueTotal[<?php echo $i; ?>]" maxlength="200" onKeyUp="compute()"/></td>
</tr>
<?php } ?>
</table>
So, how do I do with code to make it auto calculate for each row..?