need a sequential number generator in javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • masker
    New Member
    • Jun 2007
    • 1

    need a sequential number generator in javascript

    I was on the web trying to find a javascript that would allow me to input a number on my website and have it increase by a given percentage every second.

    During my search I found the Earth Population Calculator on the javascripkit.co m site. The Calculator functions just as I imagine I want my number generator to function, but I need it to present a different number.

    I work for a non profit organization that administers Head Start and other federal and state social service programs. We would like to put a counter on our website that shows the total dollars saved nationally as a result of the services agencies such as ours provide to children and parents from low-income families. For example, (for the moment I’m guessing at these numbers) let’s say that up to this point in time, $5,000,000 has been saved, and every second after that another $500 is saved.

    Could anyone help me by telling me how to create a javascript that could be allow me to input the starting number ($5,000,000) and also inputting the number I need it to increase by per second? Once I get the starting number in, and the increase per second, I want it to continue running without any further input, just as the Earth Population Calculator does.

    I’ve spent the past few days searching the internet for an answer to my problem but haven’t been able to find a sequential number generator.The Earth Population Calculator is the closest thing I’ve been able to find that demonstrates what I need.

    We are using FrontPage for our web development, but I have a new site I’ve created using Dreamweaver that I hope to be able to replace the FrontPage site with soon.

    I would really appreciate any help you can give me.

    Thank you,
    masker
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    See the setInterval method.

    Comment

    • mad genius
      New Member
      • Jan 2011
      • 3

      #3
      Solution

      It is a simple program:
      Code:
      <html>
      <head>
      <script type="text/javascript">
      var numat = 5000000
      
      function numberchange(){
      	numat += 500
      	document.getElementById("numspace").innerHTML = "$" + numat + " Saved"
      	setTimeout("numberchange()",1000)
      }
      </script>
      </head>
      <body onLoad="setTimeout('numberchange()',1000)">
      <div id="numspace">$5000000 Saved</div>
      </body>
      </html>
      Last edited by Niheel; Jan 27 '11, 04:00 AM. Reason: code tags

      Comment

      Working...