I have the following entry in a table:
<tr>
<td class="right-middle user">Name</td>
<td class="right-middle done">
<div onload="clickCounter()" id="result"></div>
</td>
<td class="right-middle check">
<img src="img/check.png" onclick="clickCounter()">
</td>
<td class="right-middle undone">
<div onload="addcounter()" id="result2"></div>
</td>
<td class="right-middle uncheck">
<img src="img/uncheck.png" onclick="addCounter()">
</td>
</tr>
and the following javascript:
function clickCounter() {
if (typeof (Storage) !== "undefined") {
if (localStorage.clickcount) {
localStorage.clickcount = Number(localStorage.clickcount) + 1;
} else {
localStorage.clickcount = 1;
}
document.getElementById("result").innerHTML = localStorage.clickcount;
} else {
document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
}
}
document.getElementById("result").innerHTML = localStorage.clickcount;
function addCounter() {
if (typeof (Storage) !== "undefined") {
if (localStorage.clickcounts) {
localStorage.clickcounts = Number(localStorage.clickcounts) + 1;
} else {
localStorage.clickcounts = 1;
}
document.getElementById("result2").innerHTML = localStorage.clickcounts;
} else {
document.getElementById("result2").innerHTML = "Sorry, your browser does not support web storage...";
}
}
document.getElementById("result2").innerHTML = localStorage.clickcounts;
I want both counters to be displayed on the screen all the time, even after refreshing the page without having to press the button to see the value. I have used this bits of code out of the table and they work fine. Can anyone help me understand why do the counters not display all the time on the screen?