javascript - Counters show permanently even if onclick -
i have following entry in 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 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, browser 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, browser not support web storage..."; } } document.getelementbyid("result2").innerhtml = localstorage.clickcounts;
i want both counters displayed on screen time, after refreshing page without having press button see value. have used bits of code out of table , work fine. can me understand why counters not display time on screen?
div elements don't have load
events. elements content other urls (like images , frames) , document do.
since using intrinsic event attributes ([problematic though are](why can't call function named clear onclick attribute? )), have been picked if had used a validator.
either:
- just run functions in script element appears after elements want interact or
- use document's load event
Comments
Post a Comment