Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: A calculation script of %?

1. ## 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?

• 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>
<title></title>

<script type="text/javascript">
// 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>

<body>
<form action="" method="post">
<input type="text" name="time" id="time">
<a href="#" id="start">Start</a>
</form>