Need a countup counter that counts up money

Hi all,

I have been trying to find a countup script that counts up cash but have been unsuccessfull.

Basically it needs to start at say £250,000 and then count up throughout the day by a total of say £3000 a day. It needs to count up by random amounts throughout the day like it is counting real time cash being added to it. So it will jump by say 20 pence, then in a few seconds jump by 7 pence, then jump by 1 pence etc... It needs to keep track of the cash amount so will need a start day so it can calculate when the page is loaded what the starting cash amount should be etc..

Any help appreciated.
Who is Participating?
Michel PlungjanConnect With a Mentor IT ExpertCommented:
Very realistic if I have to say this myself
/* random counter, (c) 2008 Michel Plungjan javascript(a) */
var startDay = new Date(2008,8,30); // 3th of September
var now = new Date();
var diff = now.getTime()-startDay.getTime()
var diffInDays = parseInt(diff/(24*60*60*1000))
var aDaysWorth=3000;
var startAmount = 250000
var todayStart = (startAmount+(aDaysWorth*(diffInDays-1)))*100; // in pence
var pencePerSecond = parseInt(300000/(24*60*60))/100;
var counter = 0;
function addComma(num,sep,decs) {
   var sep = (sep||',')
   var numStr = new String(num)
   var sign="";
   if (numStr.indexOf('-')==0) {
   var dotPos = numStr.indexOf('.');
   var commaPos = numStr.indexOf(',');
   var dec ="";
   if (sep == "." && commaPos!=-1) {
     var parts = numStr.split(',')
     dec = ","+parts[1]
     numStr = parts[0]
   else if (sep == "," && dotPos!=-1) {
     var parts = numStr.split('.')
     dec = "."+parts[1]
     numStr = parts[0]
   else if (decs) dec = (sep==',')?".00":",00"
   for (i=3;i<numArr.length;i+=3) {
   return sign+numArr.reverse().join('')+dec;
function count() {
  var rnd = parseInt(Math.random()*60);
  if ((counter > rnd && counter%rnd==0) || (counter < rnd && rnd%counter==0)) show();
  if (counter >=60) counter=1;
function show() {
var tId;
window.onload=function() { 
  tId = setInterval('count()',1000); // count the money 
Pounds:<span id="cntSpan"></span>

Open in new window

If you are using javascript alone to do what you are trying then you can keep track of the count only for that page instance. when you refresh the page or fetch the page again you will get the whole counting started again from 0 or what ever your initial data is.
If you want the count to go on for the day and if it should not be affected by when page is loaded and if it should be same all browser instances of this page then You cannot do this with javascript alone.

You can do this with AJAX.
1. Create a table that stores the count, time when last incremented
2. Create a web service that will fetch the count from this table, increment the count with a random number that should depend on the current time, last increment time and return the fetched data
3. When your page is loaded you can use ajax calls to update the page based on what frequency you want
superphonicAuthor Commented:
This seems like overkill to me, I thought it could be done with javascript alone. This is why it needs a start date and time in the script. So for example the script starts at £250,000 on 15th October 2008 at 15:43:00, and it increments at £3000 a day which is 0.035 a second, so as the day, week go on when the page is loaded it check the start date and time, calculates how much time has passed and adds that amount to the money, then it just counts up from there. The cash amount is always correct as of the day and time the browser loaded the script...  Hope that makes sense. No need for a database or anything
mm... Then you can use getTime method in javascript which will give you the number of milliseconds from 01-01-1970. Use this in your javascript to calculate the amount

use the following method to update time in interval
<script type="text/javascript">
function UpdateAmount()
var d = new Date();
//calculate and update here
         setTimeout("UpdateAmount()", <milliseconds>);
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.