Jump to content

Recommended Posts

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 post
Share on other sites

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...