i got problem here when i want to create auto calculate value of total for each row
example :
This is table data
| id | Price | Quantity | Total |
|---|---|---|---|
| 1 | 40 | 12 | 480 |
| 2 | 12 | 3 | 36 |
What i really want is create an update value form
<form action="" method="Post>
$que_= "SELECT * FROM data ;
$res_ = mysqli_query($db_conn_data,$que_);
while ($row_= mysqli_fetch_array($res_)){
<input type="text" name="price" id="price" class="form-line" style="width: 90px;" onchange="calculateAmount(this.value)" value="<? echo $row_["Price"]; ?>">
<input type="hidden" id="q" name="q" value="<? echo $row_["Quantity"]; ?>">
<input type="text" id="tot_amount" name="tot_amount" class="form-line" style="width: 90px;" value="<? echo $row_["Total"]; ?>" >
<script>
function calculateAmount(val) {
var price_ = val *document.getElementById("q").value;
/*display the result*/
var divobj = document.getElementById('tot_amount');
divobj.value = price_;}
</script>
}
</form>
So user will change the value in price input form and it will auto calculate the new Price * Quantity using javascript also replace the Total value in form
but what exactly happen right now when i change the price in the form it only calculate quantity for first row only and not by each row