Need a countup counter that counts up money

Posted on 2008-10-12
Last Modified: 2012-05-05
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.
Question by:superphonic
  • 2
LVL 13

Expert Comment

ID: 22697549
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

Author Comment

ID: 22697607
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
LVL 13

Expert Comment

ID: 22698026
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>);
LVL 75

Accepted Solution

Michel Plungjan earned 500 total points
ID: 22702408
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


Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question