updated tallys
This commit is contained in:
parent
e51da4b4c1
commit
b51f490950
@ -319,20 +319,20 @@ for (let i = 1; i <= numRows; i++) {
|
|||||||
<SCRIPT>
|
<SCRIPT>
|
||||||
//Script to tally up all of the totals
|
//Script to tally up all of the totals
|
||||||
// get all the cells in the column
|
// get all the cells in the column
|
||||||
const columnCells = document.querySelectorAll('#myTable td:nth-child(2)'); // change the selector to the desired column number
|
// Get all input elements with IDs r1 through r14
|
||||||
|
const inputs = document.querySelectorAll("#r1, #r2, #r3, #r4, #r5, #r6, #r7, #r8, #r9, #r10, #r11, #r12, #r13, #r14");
|
||||||
|
|
||||||
// initialize the total to zero
|
// Initialize a variable to hold the total
|
||||||
let total = 500;
|
let total = 0;
|
||||||
|
|
||||||
// loop through each cell in the column and add its value to the total
|
// Loop through each input element and add its value to the total
|
||||||
columnCells.forEach(cell => {
|
inputs.forEach(input => {
|
||||||
const value = parseFloat(cell.textContent.value);
|
total += Number(input.value);
|
||||||
console.log(value);
|
|
||||||
if (!isNaN(value)) {
|
|
||||||
total += value;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Output the total to the console
|
||||||
|
console.log(total);
|
||||||
|
|
||||||
// display the total in the input box
|
// display the total in the input box
|
||||||
document.querySelector('#totalBox1').value = total.toFixed(2); // change the selector to the ID of the input box
|
document.querySelector('#totalBox1').value = total.toFixed(2); // change the selector to the ID of the input box
|
||||||
</SCRIPT>
|
</SCRIPT>
|
||||||
|
Loading…
Reference in New Issue
Block a user