php - Javascript subtotal function only working on first row of table -
i implementing shopping cart , have added subtotal
field multiplies item quantity , price , returns subtotal in subtotal
column.
but, javascript function calculating subtotal first row , not rows.
here code:
<td style="text-align: left; width: 80px;">pkr<input style="width: 70px;" type="number" id="price1" value="<?php echo $values["item_price"];?>" readonly ></td> <td style="text-align: center; width: 80px;"><br/><input style="width: 60px; " form="myform" type="number" name="qty[<?php echo $values["item_id"]; ?>]" id="qty" value="<?php echo $values["item_quantity"];?>"></td> <td style="text-align: left; width: 80px;">pkr<input style="width: 70px; " form="myform" type="number" id="total" value="" readonly></td> <script type="text/javascript"> var price1=document.getelementbyid("price1").value; function calculate1() { var quantity1 = document.getelementbyid("qty").value; var x = price1 * quantity1; document.getelementbyid("total").value = x; } </script>
note: i'm calling calculate()
function on onload
event in <body>
tag.
if fields readonly
- set total value php , remove javascript function:
<input style="width: 70px; " type="number" value="<?php echo ($values["item_quantity"] * $values["item_price"]) ?>" readonly>
Comments
Post a Comment