Hi, I am having some problem to integrate my PHP & JS codes.
The PHP code -
<?php
for($i=1;$i<=3;$i++)
{
?>
<input type="text" id='rate<?php echo $i; ?>' /> * <input type="text" id='quantity<?php echo $i; ?>' onChange="updateValues(THIS);" /> = <span id='amount<?php echo $i; ?>' style="border: 2px solid black;padding:2px;"></span><br /><br />
<?php
}
?>
Total: <span id="total" style="border: 2px solid black;padding:2px;"></span>
The JS Code -
function updateValues(val) {
rate = document.getElementById(val).value;
quantity = document.getElementById(val).value;
document.getElementById(val).innerHTML = rate * quantity;
document.getElementById("total").innerHTML = total.val += val;
}
If I am defining the ID tags manually, then the thing works. But What if I need to do the same for 15 fields???