0

I got difficulties with my code. Everything is running well except the var counter and the div is not changing their values as you can see its always on 26. What I need is on my web page every time I refresh I need to see an updated value I tried searching over many forums sites etc, but no luck.

Here you can see the code :

 <head>       
    <script type="text/javascript">
    var counter = 26.00  
    var timer;

    function countUP () {
        counter = counter + Math.random();
        document.getElementById("hugee").innerHTML =(counter).toFixed(5);
    }

    </script>
</head>

<body onLoad='timer = setInterval("countUP()", 5000);'>
   <div class="col-xs-9 text-right">
     <div class="huge" id="hugee">26.00</div>
   </div>
</body>
Henry
  • 2,953
  • 2
  • 21
  • 34
  • Your code currently updates the value inside the hugee element after 5 seconds. If you need to persist the value across page refreshes, you can use the window.localStorage object. This is explained in this post: http://stackoverflow.com/questions/16206322/how-to-get-js-variable-to-retain-value-after-page-refresh – Mino Nov 29 '16 at 21:01

1 Answers1

0
only wait 5 second
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>       
    <script type="text/javascript">
    var counter = 0;
    var timer;

    function countUP() {
        counter = counter + Math.random();
        document.getElementById("hugee").innerHTML =(counter).toFixed(5);
    }

    </script>
</head>

<body onLoad='timer = setInterval("countUP()", 5000);'>
   <div class="col-xs-9 text-right">
     <div class="huge" id="hugee"></div>
   </div>
</body>
    </html>
alifallahi
  • 332
  • 1
  • 9