codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Need help to modify a formula for calculating in Javascript ?  chrbar at 20:33 on Wednesday, September 03, 2008
 

Hello,

I would like to reproduce the counter present at the top of:
http://www.ensembleverslavenir.ca/en/home.asp
I've updated the javascript by adding cookies (copy below).

But this counter calculates the tons of greenhouse gases were emitted.
My counter has to calculate the number of bottles and cans which have not been recycled.

Do you know how to change the formula for calculating to obtain an integer value (without comma) which equals 14 bottles per second?

My javascript (with cookies) is:

<script language="JavaScript" type="text/javascript">
var sTotal = 0;
if (lire_cookie('compteur'))
sTotal = parseFloat(lire_cookie('compteur'));

function gazCount(start){
sTotal=sTotal+(0.1);
document.getElementById("counter").innerHTML = r2(sTotal*2.91);
document.cookie="compteur=" + sTotal;
setTimeout("gazCount();", 100);
}
function r2(n){
ans = n * 1000
ans = Math.round(ans /10) + ""
while (ans.length < 3) {ans = "0" + ans}
len = ans.length
ans = ans.substring(0,len-2) + "." + ans.substring(len-2,len)
return ans
}
function lire_cookie(nom) {
var arg=nom+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while (i<clen){
var j=i+alen;
if (document.cookie.substring(i, j)==arg)
return arguments_cookies(j);
i=document.cookie.indexOf(" ",i)+1;
if (i==0) break;
}
return false;
}
function arguments_cookies(offset){
var endstr=document.cookie.indexOf (";", offset);
if (endstr==-1) endstr=document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

window.onload = gazCount;
</script>

Thanks a lot,
Chris









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Parsing, fish up all between <td> and </td> ... without possibility of confusion.
•  Technical problem with Visual Studio C++
•  Put confirm do you really on button instead of link
•  How Can i Create a list[Validation] in embedded Excel Object in JavaScript ?
•  Re: searching for gd::graph guide
•  Re: hash within hash
•  Re: Passing value through function then print... GONE WRONG!!
•  Need help to modify a formula for calculating in Javascript ?
•  form/cgi help


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008