Forum Moderators: open
in a table cell, with id='finish2td', onclicking calls a function that is meant to change its background to an image called 'qestion.jpg' using this code in that function:
self.finish2td.style.background='url(qestion2.jpg)';
but doesn't.
can any1 help plz?
My first suggestion is to open the page in Netscape 4.x, try the click, and then type "javascript:" in the location bar. The error messages Netscape gives for buggy javascript are not very precise, but they do pinpoint the exact spot in the code where troubles start.
If you're still having troubles after that, send me the URL in a "sticky mail" (see the menu at the top of the screen).
look at the bottom of the page and in the javascript section
If it does they're not working in IE 5.5. I didn't check the source.
About the original question... There are a couple things you can do.
First off, have you tried just:
self.style.backgound or
finish2td.style.background
istead of both? That's probably your problem.
You could also do it inline which would make sense because it doesn't look like you're calling it more than once:
onmouseover="style.background='url(qestion2.jpg)'; "
Double click on that icon and a window will appear pinpointing the beginning of the problem and a brief description.
----
Given the nature of what you're doing I guess your aiming at fairly solid browsers (IE5+ and NN6), in which case the getElementById() method is invaluable.
<script>
document.getElementById('finish2td').background = "imageURL"
</script>
NB. Note that there is no style property in the object.
This works in IE5.5 but not NN6 - Not too sure why. Try the className property that we discussed in this forum [webmasterworld.com].
Where you use the self part of the object I assume you are referring to the object the call belongs to, i.e.
<table onclick="self.background='image.jpg'">
I may be wrong but I've never seen 'self' used in this way and the correct handler should be 'this'.
<table onclick="this.background='image.jpg'">
The only time i've seen 'self' used is in relation to windows (eg. window.self.location = 'test.htm').