I have a form with this filed and by button I can add rows: book_desc[], book_pages[]. The field for sum of books_pages[] is book_pages_tot. With my javascript I want to add rows with value in each book_pages field and sum this values in a book_pages_tot field there are the total values.
This is the script: the form and fields
<form method="POST" action="addpages.php" name="books" onmouseover="javascript:sum();">
<button type="button" onClick="addRow('dataTable')"> Add pages </button>
<table id="dataTable" class="form">
<input type="text" class="form-control" name="book_pages[]" onblur="javascript:sum();">
<input type="text" class="form-control" name="book_pages_total" onblur="javascript:sum();">
</table>
</form>
The javascript:
<script language="javascript">
function sum() {
var a = parseInt(document.books.book_pages[].value);
var result = a +a[];
document.books.tot_prestazioni_A.value = result;
}
</script>
This script not work. How to sum the values put in each book_pages[] in the book_pages_tot filed?
I hope to explain my problem.
Thanks