Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-02-2009, 02:20 AM   PM User | #1
raymyn
New to the CF scene

 
Join Date: Dec 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
raymyn is an unknown quantity at this point
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?
raymyn is offline   Reply With Quote
Old 12-02-2009, 04:30 PM   PM User | #2
harbingerOTV
Senior Coder

 
Join Date: Jan 2005
Location: Memphis, TN
Posts: 1,765
Thanks: 8
Thanked 123 Times in 121 Posts
harbingerOTV will become famous soon enough
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>
__________________
Stop making things so hard on yourself.
i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis
harbingerOTV is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:20 AM.


Advertisement
Log in to turn off these ads.