Kyamagero
12-09-2009, 01:58 PM
Hello,
I have Javascript code that was developed for purposes of having a population estimator on an organisation website. It used to work but when we tried it recently, it failed. Can someone look into the code and help.
I have attached a .txt with html and javascript code. The javascript is in the header section.
To see what I see now, go to:
http://realtechgrup.com/demos/popsec/test.php
I am supposed to see a clock.
please someone look through and help.
Thanks,
Ronald
jscheuer1
12-09-2009, 05:08 PM
<script type="text/javascript">
var cP;
var bP=23317560;
var gP,bD=new Date(2000,06,01),dstO = 1;
gP=bP * 0.0296;
var timerID = null;
var timerRunning = false;
function stopclock () {
if(timerRunning) cleartimeout(timerID);
timerRunning=false;
}
function startclock () {
stopclock();
showtime();
}
function showtime () {
var tD,cPs,cPt,ts,nT=new Date(),tf;
tD=(nT - bD)/1000;
tf=(tD/31536000);
wP=parseInt(6080141683 + (77258877 * tf),10);
cP= parseInt(bP + (gP * tf),10);
cPt = "Uganda:<b> " + fstr(cP.toString(),",") + "</b><br>World:<b> " + fstr(wP.toString(),",")+"</b>";
cPs = cPt.toString();
MM_setTextOfLayer('popLayer','',cPs);
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
function MM_findObj(n, d) { //v3.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.getElementById) x=d.getElementById(n); for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
function MM_setTextOfLayer(objName,x,newText)
{ //v3.0
if ((obj=MM_findObj(objName))!=null) with (obj)
if (document.layers)
{document.write(unescape(newText)); document.close();}
else innerHTML = unescape(newText);
}
function fstr(n,t){var nf,l=n.length,p; if (l>3) {p = (l % 3);
if (p==0) p=3; nf= n.substr(0,p);
do {nf = nf + t + n.substr(p,3); p+=3;} while (p<l);}return nf;}
</script>
Kyamagero
12-10-2009, 03:28 PM
Thanks jscheuer1,
It works. What was wrong?
Thanks again,
Ronald
jscheuer1
12-10-2009, 04:10 PM
Two things, and not really completely wrong, more like outdated. It used document.all instead of document.getElementByID - this causes it to fail in several browsers if the page has a valid URL DOCTYPE. That one is just because of the age of the code. It also tested for Netscape 4 type browsers in such a way that erroneously caught numerous modern browsers that no longer can use the old NS 4 syntax. That was sort of wrong even then, as there were ways even then to test for the syntax, rather than the browser. If that had been done then, that part would not have caused a problem now.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.