I have an issue regarding javascript and arrays. Below is my html site
<?php for ($x = 1; $x <= $_SESSION['qty_voucher']; $x++) { ?>
<td>Qty</td>
<td>
<input type="number" step = "any" class="form-control" id="voucherqty[]" name="voucherqty[]" onkeyup="calc()" />
</td>
<td>Amount</td>
<td>
<input type="number" step = "any" class="form-control" id="voucheramount[]" name="voucheramount[]" onkeyup="calc()" />
</td>
<td>Total</td>
<td>
<input type="number" step = "any" class="form-control" id="vouchertotal[]" name="vouchertotal[]" />
</td>
<?php } ?>
and these are the javascript i'm trying to do it
function calc() {
var table = document.getElementById("tablenum");
var rowCount = table.rows.length;
for (var i = 0; i < rowCount; i++) {
var totalNum = parseFloat(document.getElementById("voucherqty[]").value) * parseFloat(document.getElementById("voucheramount[]").value);
document.getElementById('vouchertotal[' + i + ']').value = totalNum;
}
}
my objective is to loop through the input field and Qty * Amount = Total for each of the array row.
I believe I'm missing out something but I dont know what it is. Thanks!