I am trying to find an adjustable counter that I can use on our site to show a steady increase in dollars collected. I guess similar to the the national debt counter, but the values need to be programmable and adjustable (starting amount, increment amount, speed, etc) by me.

It is only a representation counter and does not need to collect data from anywhere. We will update and adjust real values on a regular basis as the data is received through other sources.

Any suggestions would be appreciated.

9 Years
Discussion Span
Last Post by VisibleFrog

try a global variable name:

var counter;

To make it global you must state this outside of the functions that will manipulate its value.

Edited by mike_2000_17: Fixed formatting


This is actually rather simple, as far as these things go.
Do you know any JavaScript?

This code is just off the top of my head; I haven't tested it.

<script language="JavaScript">
<!-- //
var start_time = new Date("September 7, 2009 14:00 GMT"); // starting date and time
var start_amount = 2000; // amount at starting time
var time_unit = 604800000; // in this example, one week
// note: time unit is specified in milliseconds
// 1000 milliseconds = 1 second
var change_per_time_unit = 300; // amount of change per time unit
var now = new Date();
var elapsed_time = now.getTime() - start_time.getTime();
var elapsed_time_units = elapsed_time / time_unit;
var current_amount = start_amount + (change_per_time_unit * elapsed_time_units);
document.write("** Amount collected so far: $"+(current_amount.toFixed(2))+" **");
// -->

@Rob, How could I make it so the numbers are counting up "live" instead of on browser refresh?

Many Thanks!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.