I have a table with ping-pong standings tracking the players' wins and losses. I implemented a feature that allows the players to put in their own games and update the score, but the problem is that once the page refreshes, any changes made are lost, and the standings revert to the original table hardcoded in the HTML file. I thought about writing and saving the new table to a separate HTML file and importing that over the old table whenever I update the scores, but I can't figure it out. Can I do this with local storage, or does that not save information permanently?
Any suggestions?
Here's the relevant code
function updateScores() {
table = document.getElementById("Standings");
rows = table.rows;
for (i = 1; i < (rows.length - 1); i++) {
var wins = rows[i].cells[2];
var losses = rows[i].cells[3];
var winNodes = parseInt(wins.childNodes.item(0).data);
var lossNodes = parseInt(losses.childNodes.item(0).data);
var percentage = String(Math.round((winNodes / (winNodes + lossNodes)) * 100)) + "%";
if (winNodes == 0) {
document.getElementById("win" + String(i)).innerHTML = "0%";
} else {
document.getElementById("win" + String(i)).innerHTML = percentage;
}
}
}
updateScores()
<table class="center" id="Standings">
<tr>
<th onclick="sortTable(0)">Player</th>
<th onclick="sortTable(1)">Win Percentage</th>
<th onclick="sortTable(2)">Wins</th>
<th onclick="sortTable(3)">Losses</th>
</tr>
<tr id="Jason">
<td>Jason</td>
<td id="win1">0%</td>
<td>3</td>
<td>4</td>
</tr>
<tr id="Yair">
<td>Yair</td>
<td id="win2">0%</td>
<td>18</td>
<td>2</td>
</tr>
• • •
</table>