Savings Counter Module for DotNetNuke?
I have searched long and hard for module that would show Customer Savings(in $$). There are two ways I wish to possibly implement this.
Method One: Customer enters a "base" $$ amount, start date, and an incrementing value per time period Ex: Base=$1,000,000; Start:1/1/2010; Increment=$100; Time Period=Minute This would diplay $1,432,000 after exactly 3 days (3days*24hrs*60mins*$100=$432,000 since 1/1/2010) Each time the person refreshed the page, the amount saved would be calculated based on the difference in time between the start date and current date, and displayed to the user.
Method Two:(IDEAL) Same setup as above, but savings would be updated every second (and possibly with some kind of odometer-looking counter that is constantly rolling over).
Has anyone seen or heard of any module like this? I have searched high and low and the only "counters" I can find are hit counters and such. If no one is aware of any pre-existing modules, how could this be coded into a DotNetNuke module? I have not yet delved into the world of coding custom modules. I have only tweaked other modules to make them work the way I need. Any and all help is greatly appreciated!
UPDATE: Here is my final code. In the "footer" section (under Settings) of DNN HTML module: $(document).ready(function(){
setTimeout('countit()',1); //1 makes it display the value quickly after loading
});
function countit()
{
var amountperyear=4000000; //THIS IS THE ONLY NUMBER TO EDIT EACH YEAR
var msperyear=31536000000; //milliseconds per year
var today=new Date();
var startdate=new Date(today.getYear(),0,00); //January 1, of the current year at midnight?
var diff=Math.ceil((today.getTime()-startdate.getTime())); //Time difference in milliseconds
var newvalue=(diff*(amountperyear/msperyear)); // (# of ms) * (amount/ms)
var displayvalue=newvalue.toLocaleString(); //Convert to currency formatting
$("#mycounter").html("$"+displayvalue);
setTimeout('countit()',500); //Have it update twice per second
}
</script>
In the Content section of the DNN HTML module:
<center>
This year, we've saved our customers:
<b><div id="mycounter"><i>Loading...</i></div></b>
</center>
NEW ISSUE: This script is only working in Internet Explorer. In Chrome and Firefox the result in off by more than a billion. I'm not quite sure what is causing the issue, but I believe it has to do with the date math or the .toLocaleString() perhaps? Anyone who might have run into this issue before? Any insight or links would be greatly appreciated! For now, I simply but in some conditional comments but this can't be a permanent fix!
<![if !IE开发者_JAVA百科]>You must use IE to view this<![endif]-->
Create an HTML file on your local hard drive and put this in it. Then open it in your web browser. It will start incrementing a number. What you are looking for does not exist in DNN but it can be done with some simple Javascript. This should get you started.
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript">
var count=5;
$(document).ready(function(){
setTimeout('countit()',1000);
});
function countit()
{
var startmoney = 10;
var today=new Date();
var startdate=new Date(2010, 10, 01); //this is actually 11-1-2010 the 10 is 0 based so actually month 11
var one_day=1000*60*60*24;
var diff=Math.ceil((today.getTime()-startdate.getTime())/(one_day));
//diff is the main factor which is the difference in days between startdate & today
count=count*2;
var newvalue=startmoney*count*diff;
$("#mycounter").html(newvalue);
setTimeout('countit()',1000);
}
</script>
</head>
<body
<div id="mycounter"></div>
</body>
</html>
精彩评论