function calculate(elementID) {
var mainRow = document.getElementById(elementID);
var myBox1 = mainRow.querySelectorAll('[name=qty]')[0].value;
var myBox2 = mainRow.querySelectorAll('[name=price]')[0].value;
var total = mainRow.querySelectorAll('[name=total]')[0];
var myResult1 = myBox1 * myBox2;
total.value = myResult1.toFixed(2);
}
Note: The javascript function works when the names aren't arrays. The html inputs have to be arrays because I'm using $_POST with php to add them into another form and database. I'm also adding rows dynamically using a button, which is why I'm using arrays.