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.

Recommended Answers

All 3 Replies

try a global variable name:

var counter;

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

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))+" **");
// -->
</script>

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

Many Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.