Page 1 of 1

Javascript error

Posted: Sun Jun 18, 2006 12:44 am
by jabbaonthedais
I'm using this javascript code to count down from 30 minutes. The original code would reset to 30 when it reached 0. I modifed the code to display a link to refresh the page, but when it reaches 0, displays the link, I get an error on the page:

"document.getelementbyID(....) is null or not an object"


Here's the code:

Code: Select all

/* the timer */

        function StartTimer()
        {

        	setTimeout("UpdateTimer()", 1000);

        	resetmin=30;
        	resetsec=0;

        	if (min < 0) {
        		min=resetmin;
        		sec=resetsec;
        	}

        	if (sec < 10) {
        		temp="0";
        	}
        	else {
        		temp="";
        	}

        	document.getElementById("idTimer").innerHTML="<span id=\"idMin\" style=\"font-weight: normal; \"><font size='5'>"+min+"</font></span>:<span id=\"idSec\" style=\"font-weight: normal; \"><font size='5'>"+temp+sec+"</font></span>";

        }

        function UpdateTimer()
        {

        	setTimeout("UpdateTimer()", 1000);

        	sec--;
        	if (min == 0 && sec == 0)
        	{
        	document.getElementById("idTimer").innerHTML="<a href='javascript:history.go(0)'>refresh</a>";
            return;
        	}

        	if (sec < 0)
        	{
        		sec = 59;
        		min--;
        	}

        	document.getElementById("idMin").innerHTML=min;
        	var temp;

        	if (sec < 10) {
        		temp="0";
        	}
        	else {
        		temp="";
        	}

        	temp = temp+sec;
        	document.getElementById("idSec").innerHTML=temp;

        }
The part I modified in was:

Code: Select all

document.getElementById("idTimer").innerHTML="<a href='javascript:history.go(0)'>refresh</a>";
            return;

I did look up javascript functions but I'm not at all familiar with javascript references like php. I wish there was a javascript.net like php.net. :(

Posted: Sun Jun 18, 2006 6:13 am
by s.dot
is 'idTimer' the id of an element on your page?

Posted: Sun Jun 18, 2006 7:15 am
by jabbaonthedais
Yeah, I put this in my page to display the countdown:

Code: Select all

<font face='Verdana' size='5'>
<div id='idTimer' style='color: black'></div>
<script language='JavaScript'> StartTimer(); </script>
</font>

Posted: Sun Jun 18, 2006 7:21 am
by jabbaonthedais
Another problem is when you load the page in Firefox, the font is big (like it should be), but upon loading it reduces to the default font size. Weird.