Javascript error

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
jabbaonthedais
Forum Contributor
Posts: 127
Joined: Wed Aug 18, 2004 12:08 pm

Javascript error

Post 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. :(
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

is 'idTimer' the id of an element on your page?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
jabbaonthedais
Forum Contributor
Posts: 127
Joined: Wed Aug 18, 2004 12:08 pm

Post 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>
jabbaonthedais
Forum Contributor
Posts: 127
Joined: Wed Aug 18, 2004 12:08 pm

Post 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.
Post Reply