aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes document[].src returning null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "document[].src returning null" Watch "document[].src returning null" New topic
Author

document[].src returning null

jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
I have the following JavaScript:

The default image comes up fine, however when I move the mouse to the image, I get an error stating that document[...] is null or not an object. I've been following a tutorial, and this example is pretty much identical. Is there something wrong with the JavaScript code, or is it something with my system?
Thanks!
Jason
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

i cant spot the error but im not an expert on js. one possibility is that you accidently have said picl instead of pic1, or vice versa


SCJP
Visit my download page
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Found the problem, and it's of course the simple solution.

I was refreshing one browser session while I had another one open, also. Wasn't actually refreshing. Once I closed both browsers and re-opened, worked fine

Now my problem is trying to figure a way to get a running clock working without actually sticking the clock into an input form. Wish HTML had a label type thing that you could repeatedly update, but that's a topic for another post
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
How about this?
<HTML>
<HEAD><TITLE>Test Page</TITLE></HEAD>
<BODY>
<DIV ID="CLOCK">
</DIV>
<SCRIPT LANGUAGE="JAVASCRIPT">
setInterval("showDate()",1000)
function showDate()
{
var myDate = new Date()
var hours = myDate.getHours()
var minutes = myDate.getMinutes()
var seconds = myDate.getSeconds()
if(hours < 10)
{
hours = '0' + hours
}
if(minutes < 10)
{
minutes = '0' + minutes
}
if(seconds < 10)
{
seconds = '0' + seconds
}
CLOCK.innerHTML = "<h1>" + hours + ":" + minutes
+ ":" + seconds+ "</h1>"
}
</SCRIPT>
</BODY>
</HTML>
It will work in IE, anyway. You would have to cross-browserize the code to make it work in Netscape.
[ April 11, 2002: Message edited by: Bodie Minster ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: document[].src returning null