Results 1 to 4 of 4

Thread: Can someone help me to know why my Javascript code does not display what it should

  1. #1
    Join Date
    Dec 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Can someone help me to know why my Javascript code does not display what it should

    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

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <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>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Kyamagero (12-10-2009)

  4. #3
    Join Date
    Dec 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks jscheuer1,

    It works. What was wrong?

    Thanks again,

    Ronald

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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