View Full Version : Resolved Counter script not working

05-24-2009, 08:25 AM
Hi, I am trying to make this script work as a population counter but I don't know how to use Java. Can you please help me with any suggestions on how to make it work? I have already been trying for three days..

Thank you,


<div id = "AustPop"></div>

<script type = "text/javascript">

var basisDate = new Date(2009,4,24,05,46,36).getTime(); // 24 May 2009 at 05:46:36 (Canberra Time)
var basisPop = 21769052; // population as at that time

function ozPop() {
var now = new Date();
var now = new Date().getTime();
var diff = (now - basisDate)/60000; // minutes
var newPop = parseInt((diff/1.5) + basisPop); // increase by 1 every 1.5 minutes
newPop = newPop.toString();
newPop = addCommas(newPop); // format with commas
msg = "The population of Australia as of this moment is estimated to be:- ";
document.getElementById("AustPop").innerHTML = msg + newPop;

window.setTimeout("ozPop()",30000); // update each half minute

function addCommas(nStr) {
nStr = nStr.replace(/[^0-9\.]/g,"");
var rgx = /(\d+)(\d{3})/;
while (rgx.test(nStr)) {
nStr = nStr.replace(rgx, '$1,$2');
return nStr;


Philip M
05-24-2009, 09:56 AM
It works fine for me. What is the problem?

Have you called it with
<body onload = "ozPop()">

Java and Javascript are entirely different programming languages, in spite of the confusingly similar names.

And why have you started a new thread?

05-24-2009, 01:25 PM
Hi Philip,

The script you wrote works perfectly:thumbsup: thank you very much for you help. Regardless of whether or not it worked, I absolutely appreciate and understand that you made a specific effort to help me.
I hadn't put <body onload = "ozPop()"> at the beginning, I had tried putting <body>, but like I said, I've never used JavaScript before so what may be obvious to a professional like yourself is difficult for me. Also, the reason I made a new thread was because the original thread didn't have a post icon, and the title wasn't bold anymore, it seemed as though it had been marked as resolved..(I am also new to this forum and have since read the 'posting guidelines.')

Again, thank you very much for taking the time to help.


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum