SherryG
asked on
Error: 'document.Clock.document' is null or not an object
I am getting this error (Error: 'document.Clock.document' is null or not an object) when executing the following code:
<% 'Detecting browsers used by the users
set Brow=Server.CreateObject(" MSWC.Brows erType")
BrowType=Brow.Browser
%>
<html>
<head>
<title>Header Page</title>
<META HTTP-EQUIV = "Pragma" CONTENT="no-cache">
<SCRIPT LANGUAGE="JavaScript">
<!--
var timerID = null
var timerRunning = false
var TimeDiff = null
function stopclock(){
if(timerRunning)
clearTimeout(timerID)
timerRunning = false
}
function startclock(){
// computing time difference between the server and the client machine
var now = new Date()
var ClientT = Date.UTC(now.getFullYear() ,now.getMo nth(),now. getDate(), now.getHou rs(),now.g etMinutes( ),now.getS econds())
TimeDiff=arguments[0]*1000 -ClientT
// Make sure the clock is stopped
stopclock()
showtime()
}
function showtime(){
var dayList = new Array("Sun","Mon","Tue","W ed","Thu", "Fri","Sat ")
var monthList = new Array("Jan","Feb","Mar","A pr","May", "Jun","Jul y","Aug"," Sep","Oct" ,"Nov","De c")
var adjust = null
var now = new Date()
var ClientT = Date.UTC(now.getFullYear() ,now.getMo nth(),now. getDate(), now.getHou rs(),now.g etMinutes( ),now.getS econds())
ClientT = ClientT+now.getTimezoneOff set()*6000 0+TimeDiff
var now = new Date(ClientT)
var seconds = now.getSeconds()
var minutes = now.getMinutes()
var hours = now.getHours()
var date = now.getDate()
var day = now.getDay()
var month = now.getMonth()
var timeValue = "" + dayList[day] + ", "
timeValue += monthList[month] + " "
timeValue += date + ", "
timeValue += ((hours > 12) ? hours - 12 : hours)
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " PM " : " AM "
<%if BrowType="IE" then%>
Clock.innerHTML = timeValue;
<%else%>
document.Clock.document.wr ite("<FONT face='Verdana,Arial' color=crimson size=1><B><U>"+timeValue+" </U></B></ FONT>")
document.Clock.document.cl ose()
<%end if%>
timerID = setTimeout("showtime()",10 00)
timerRunning = true
}
-->
</SCRIPT>
</head>
<% date1=cdate("1/1/1970")
date2=now
TimeDiff=datediff("s",date 1,date2)
%>
<BODY onLoad="startclock(<%=Time Diff%>)">
<TABLE Height=85 width=500>
<TR>
<TD align=middle><FONT color=mediumblue face=Arial size=5 >
<STRONG>IE-597D Response Surface Methodology</STRONG></FONT >
</TD></TR>
<TR>
<TD align=middle><FONT color=mediumblue face=Arial size=4 >Process Simulator</FONT>
</TD></TR>
<TR>
<TD align=right>
<%if BrowType="IE" then%>
<FONT face="Verdana,Arial" color=crimson size=1><B><U>
<DIV id=Clock> </DIV></U>< /B></FONT>
<%else%>
<LAYER ID="Clock" left="350" top="80"> </LAYER>
<%end if%>
</TD>
</TR>
</TABLE>
</body>
</html>
NOTE: I took this code from an IIS3 server and am trying to run it on an IIS5 server. I don't know much about ASP or javascripting.
Any suggestions?
<% 'Detecting browsers used by the users
set Brow=Server.CreateObject("
BrowType=Brow.Browser
%>
<html>
<head>
<title>Header Page</title>
<META HTTP-EQUIV = "Pragma" CONTENT="no-cache">
<SCRIPT LANGUAGE="JavaScript">
<!--
var timerID = null
var timerRunning = false
var TimeDiff = null
function stopclock(){
if(timerRunning)
clearTimeout(timerID)
timerRunning = false
}
function startclock(){
// computing time difference between the server and the client machine
var now = new Date()
var ClientT = Date.UTC(now.getFullYear()
TimeDiff=arguments[0]*1000
// Make sure the clock is stopped
stopclock()
showtime()
}
function showtime(){
var dayList = new Array("Sun","Mon","Tue","W
var monthList = new Array("Jan","Feb","Mar","A
var adjust = null
var now = new Date()
var ClientT = Date.UTC(now.getFullYear()
ClientT = ClientT+now.getTimezoneOff
var now = new Date(ClientT)
var seconds = now.getSeconds()
var minutes = now.getMinutes()
var hours = now.getHours()
var date = now.getDate()
var day = now.getDay()
var month = now.getMonth()
var timeValue = "" + dayList[day] + ", "
timeValue += monthList[month] + " "
timeValue += date + ", "
timeValue += ((hours > 12) ? hours - 12 : hours)
timeValue += ((minutes < 10) ? ":0" : ":") + minutes
timeValue += ((seconds < 10) ? ":0" : ":") + seconds
timeValue += (hours >= 12) ? " PM " : " AM "
<%if BrowType="IE" then%>
Clock.innerHTML = timeValue;
<%else%>
document.Clock.document.wr
document.Clock.document.cl
<%end if%>
timerID = setTimeout("showtime()",10
timerRunning = true
}
-->
</SCRIPT>
</head>
<% date1=cdate("1/1/1970")
date2=now
TimeDiff=datediff("s",date
%>
<BODY onLoad="startclock(<%=Time
<TABLE Height=85 width=500>
<TR>
<TD align=middle><FONT color=mediumblue face=Arial size=5 >
<STRONG>IE-597D Response Surface Methodology</STRONG></FONT
</TD></TR>
<TR>
<TD align=middle><FONT color=mediumblue face=Arial size=4 >Process Simulator</FONT>
</TD></TR>
<TR>
<TD align=right>
<%if BrowType="IE" then%>
<FONT face="Verdana,Arial" color=crimson size=1><B><U>
<DIV id=Clock> </DIV></U><
<%else%>
<LAYER ID="Clock" left="350" top="80"> </LAYER>
<%end if%>
</TD>
</TR>
</TABLE>
</body>
</html>
NOTE: I took this code from an IIS3 server and am trying to run it on an IIS5 server. I don't know much about ASP or javascripting.
Any suggestions?
Oh, and to see the value in browser print it like this:
<BODY onLoad="startclock(<%=Time Diff%>)">
BrowType: <b><%=BrowType%></b><br>
<BODY onLoad="startclock(<%=Time
BrowType: <b><%=BrowType%></b><br>
ASKER
Very strange. When I added that line and ran the page I got brow type = Netscape, but I was using IE 6. When I ran the page on a different machine with netscape I got brow type = default.
Any thoughts?
Any thoughts?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That seems to work great. Thanks.
You are welcome.
ASKER
Woops. I just noticed that everytime I go to the page the date and time it displays and starts counting from is Wed, Dec 31, 11:00:00 PM.
Any idea why it might do that? I checked and the time is correct on the server.
Any idea why it might do that? I checked and the time is correct on the server.
Do you pass the correct offset in the body tag:
<BODY onLoad="startclock(<%=Time Diff%>)">
The offset has to be in miliseconds.
Check the value again with the print.
Like this:
<BODY onLoad="startclock(<%=Time Diff%>)">
TimeDiff: <b><%=TimeDiff%></b><br>
<BODY onLoad="startclock(<%=Time
The offset has to be in miliseconds.
Check the value again with the print.
Like this:
<BODY onLoad="startclock(<%=Time
TimeDiff: <b><%=TimeDiff%></b><br>
ASKER
When I pasted those two lines to my page nothing displays after TimeDiff: and I get (undefined, undefined NaN, NaN:NaN:NaN AM) where the date used to appear.
ASKER
I think I got it. I added the
<% date1=cdate("1/1/1970")
date2=now
TimeDiff=datediff("s",date 1,date2)
%>
back in just before my body tag and it seems to be working.
Sorry for being such a putz at this.
<% date1=cdate("1/1/1970")
date2=now
TimeDiff=datediff("s",date
%>
back in just before my body tag and it seems to be working.
Sorry for being such a putz at this.
Put this lines before the <body> tag:
<%
date1=cdate("1/1/1970")
date2=now
TimeDiff=datediff("s",date 1,date2)
%>
<%
date1=cdate("1/1/1970")
date2=now
TimeDiff=datediff("s",date
%>
Ok, you managed it :)
Perhaps is the string NOt "IE" event when it is talking to IE, perhaps it is lowercase, or some additional information.
<%if BrowType="IE" then%>