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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

debt counter 1

Status
Not open for further replies.

EnergyTed

Programmer
Jan 27, 2005
68
GB
I am trying to achieve a simple script to show debt being counted continuously. Can anyone help me get started?
 
Could you provide a bit more explanation of the problem?

For example: What specifically are you trying to achieve? Where is the data for the debt coming from? Input from the user? Pulled from a database? Is the data for the debt calculated dynamically, or statically to be shown in a report type form? Are there any specific equations you need to use for this problem that you can provide?

Your question is too vague for us to provide a concise answer.

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 

I am looking for something similar to the above link. The data for the debt will come from national stats, no input from the user is required, hopefully it will be calculated dynamically ?, an example would be -

debt = 1000, 10% a year inflation, therefore I would like my script to show 1000 visually increasing whether its being viewed or not.
 
In the link you provided it seems that they are starting with some root number and then doing some calculation based on the date/time of the system clock. If you study the 1000's place carefully, you'll see that it increments by 2 every 1 second. I'm guessing that the data on the page isn't accurate at all, used mostly for "show".

Nevertheless, here's how you'd set something like that up in javascript. I'll use the getTime() method of the date object to return an incrementing number. I'll leave all the debt-calculation to you:

Code:
<script type="text/javascript">

function startIncrement() {
   //this sets the incrementTime() function to be ran every 10 milliseconds
   window.setInterval("incrementTime()", 10);
}

function incrementTime() {
   var obj = document.getElementById("blah");
   //set the text for the <div> equal to the milliseconds returned by getTime()
   obj.innerHTML = new Date().getTime();
}

//assign the function to run when the page is done loading
window.onload = startIncrement;

</script>

<body>

<div id="blah"></div>

</body>

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
Sorry for my ignorance kaht, but will this visually show the debt being increased ?

Many thanks

 
copy the snippet that I provided, paste it into a new file on your desktop named test.html, double click the newly created file and see for yourself

I didn't post code for reference, I posted it so that you'd have a working example to build off of [smile]

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top