anshulmahipal Posted May 17, 2015 Share Posted May 17, 2015 hello all, Recently i created a fuction auto incriment of no. in html pages but there is a problem in this when the html page load again the counting start with its origin the fuction is: <script type="text/javascript">var number = 1;function increment(){ number++; showNumber(number); number = number;}function showNumber(num){ document.getElementById("displayDiv").innerHTML = num;}window.onload = function(){ setInterval("increment()", 1000); showNumber(number);}</script> <div id="displayDiv"></div> where is the problem? why it cant start from its last updated value Link to comment Share on other sites More sharing options...
Ingolme Posted May 17, 2015 Share Posted May 17, 2015 Javascript doesn't have memory. Everything resets when you reload the page. You can store the value in a cookie or in localstorage if you want it to be remembered in the future. Cookies and localstorge will remember the number for an individual user, but if you want the number to be global to the website, you will need a server-side language. Javascript can't do it. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now