Once I use the script I did in JavaScript, it only changes the value of the first textbox inside a while loop. Here is my php code:
<?php
$edittable=$_POST['selector'];
$N = count($edittable);
for($i=0; $i < $N; $i++)
{
$result = mysql_query("SELECT * FROM inventory where assetid='$edittable[$i]'");
while($row = mysql_fetch_array($result))
{
extract($row);
?> <tr>
<td></td>
<td><?php echo $assetdesc; ?></td>
<td><?php echo $serialno ?></td>
<td><select class="form-control" name="qtyunit" id="qtyunit" onchange="calculate()" required>
<option>----</option>
<?php
$qtyfirst = 1;
for($new = $qtyfirst ; $new <= $assetqty; $new++){
?>
<option><?php echo $new; ?></option>
<?php
}
?>
</select></td>
<td><?php echo "₱".number_format((float)$purchaseprice, 2, '.', ','); ?></td>
<input value = "<?php echo $purchaseprice; ?>" name="hiddencost" id="hiddencost" hidden>
<td><input class="form-control" name="totalcost" id="totalcost" readonly></td>
</tr>
<?php
}
}
?>
Here is my JavaScript:
<script type="text/javascript">
function calculate() {
var myBox1 = document.getElementById('qtyunit').value;
var myBox2 = document.getElementById('hiddencost').value;
var result = document.getElementById('totalcost');
var myResult = myBox1 * myBox2;
result.value = myResult;
}
</script>