Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    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?

  • #2
    Senior Coder
    Join Date
    Jan 2005
    Memphis, TN
    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.

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
    <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();
    		var percentage = basepercent * $("span.num:eq(1)").text()
    		var percentage = basepercent * $("span.num:eq(1)").text()
          var total = 0;
    		$("span.num").each(function() {
    			total += parseFloat($(this).text()) || 0;
    		total = Math.round(total);
    		$("#counter span").text(total);
        }, speed); 
    // end
    <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>
    <div id="counter">Your counter: <span class="num"></span></div>
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts