Quote:
Originally Posted by Bama
So I was looking around for a script kinda' like the debt clock but on a much smaller scale and after a few hours of looking finally came across a thread that got close to what I wanted.
Variables I'd like to have:
Count up in cents and show that in the count
Set how much (in dollars) it counts up every 24 hours (thinking around 5 or 6 bucks/day)
Set starting amount (does this already)
PHP Code:
<html>
<head>
<script type="text/javascript">
function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
var ms=today.getTime();
var moneySavedPerSecond = 5.47;/*in dollars*/
var startDate = 1301802459944;/*In milliseconds from Jan 1, 1970*/
var startSavings = 1000;
var totalSaved=Math.round(((ms-startDate)/1000)*moneySavedPerSecond+startSavings);
// add a zero in front of numbers<10
m=checkTime(m);
s=checkTime(s);
totalString = totalSaved+''; //converts number into string
totalString = addCommas(totalString); //calls the addCommas function and returns the value with the commas
document.getElementById('txt').innerHTML="Our customers have saved $"+totalString+" with us.";
t=setTimeout('startTime()',100);//time in milliseconds for the total to be updated
}
function checkTime(i)
{
if (i<10)
{
i="0" + i;
}
return i;
}
function addCommas(nStr) //function from http://www.mredkj.com/javascript/nfbasic.html
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
</script>
</head>
<body onload="startTime()">
<div id="txt">If you can read this something went wrong.</div>
</body>
</html>
|
I'm bored if you have $50.