Enjoy an ad free experience by logging in. Not a member yet? Register.

Results 1 to 2 of 2
Thread: A calculation script of %?

12022009, 03:20 AM #1
 Join Date
 Dec 2009
 Posts
 1
 Thanks
 0
 Thanked 0 Times in 0 Posts
A calculation script of %?
I was woundering if their is a such html code that I input a value (say 1000) and ti automatically adds 5% to it every say 30 minutes? Is their a such script?
Like if someone said the number 1000 on the website, and locked in the value. They need to get 10% every 30 minutes. Is taht possible?
12022009, 05:30 PM
#2
 Join Date
 Jan 2005
 Location
 Memphis, TN
 Posts
 1,801
 Thanks
 8
 Thanked 131 Times in 129 Posts
here's a jQuery solution:
Since you didn't specify, this example will add 10% of the entered value exponentially to the total value. Ie, every 3 seconds it will take 10% of the total and add it to the toal. Then 3 seconds later it will find 10% of the new total and ad it to it and so on.
Should be pretty straight forward as I added comments to the JS by the areas that need to be changes to suit your needs.
Code:<!DOCTYPE html PUBLIC "//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { // begin // below is the amount you want to add in percentages (decimal) var basepercent = ".10"; //below is the speed in which you want to add in miliseconds var speed = "3000"; //that's 3 seconds. 30 minutes would be 1800000 $("#start").click(function () { var starttime = $("#time").val(); $("span.num:eq(1)").text(starttime); var percentage = basepercent * $("span.num:eq(1)").text() $("span.num:eq(0)").text(percentage); setInterval(function(){ var percentage = basepercent * $("span.num:eq(1)").text() $("span.num:eq(0)").text(percentage); var total = 0; $("span.num").each(function() { total += parseFloat($(this).text())  0; }); total = Math.round(total); $("#counter span").text(total); }, speed); }); // end }); </script> </head> <body> <form action="" method="post"> <input type="text" name="time" id="time"> <a href="#" id="start">Start</a> <div>Your multiplier: <span class="num"></span></div> </form> <div id="counter">Your counter: <span class="num"></span></div> </body> </html>