Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto-incrementing counter 1

Status
Not open for further replies.

TheVampire

Programmer
May 1, 2002
828
US
Good day,

I'm trying to add an Auto-incrementing counter to my site ( ). I want the counter to update once every few seconds, with a dollar amount that shows the total trade debt from the USA to communist china. Similar to what is shown on for the cost of the Iraq war.

I've not got a lot of experience at HTML, as my site was designed by me with a WYSIWYG editor provided by Earthlink. I do have the ability to FTP my pages, so I can add whatever HTML I need to the page and upload it no problem.

Basically, what do I need to do? I've looked around for code for this and viewed the source of the projectbillboard page and found what I *think* does the work for the counter, but I don't really understand the code behind it enough to be able to modify it for my particular desire. I have a lot of experience in other types of programming, so I should be able to get it working if someone can give me a push in the right direction. :)

Thanks,

Robert
 
The best way to do this on the webpage only would be to use javascript. Call a function that updates the counter with a setTimeout("setCounter()",3000")

The most common implementation is a javascript clock

--Chessbot
 
Can anyone be a little more specific? How do I get it to format into dollar amounts, etc.

Thanks,

Robert
 
How are you getting the numbers?

--Chessbot

The program didn't do anything wrong; it did exactly what you told it to!
 
Basically I'm taking the amount at a specific date, and extrapolating based on what date/time it is from that point, figuring that it increases X amount per second. I'm still working the exact number out, but I wanted to get the code figured first.

Robert
 
Assuming you want the counter to display right on the screen:

Code:
var timeout;

function displayCounter()
{
  var count = getCount();

  document.getElementById("counter").innerHTML = count;

  timeout = setTimeout("displayCounter()",3000);
}

This function assumes you have a function getCount() that finds the value you need.

Your body tag should include:
Code:
onLoad="displayCounter();"

and where you want the counter to appear, put:
Code:
<div id="counter"></div>

The counter can be styled using CSS.

--Chessbot

The program didn't do anything wrong; it did exactly what you told it to!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top