Click to See Complete Forum and Search --> : netscape, relative td, and images


bisqui
01-18-2003, 01:31 PM
Let me explain what I'm trying to do here. I have some code in place to switch the background image of a table cell in Netscape. It looks like this(for the sake of brevity, i'm leaving out extraneous tags) :

function changeBg(id, img)
{
document.layers[id].background.src = img;
}

<style>
.relative { position:relative; }
</style>

<td width="100" class="relative" id="snBg">
<table height="100" background="./images/trans.gif">
<tr>
<td width="100" height="100" valign="top">
<img src="./images/trans.gif" width="19" height="100" name="label"/>
</td>
</tr>
</table>
</td>


Essentially what this does in NS is convert the td assigned the relative class into a layer. Then by calling changeBg with the td/layer's id, you can set the bg image. This works fine. My problem arises when I try to access the "label" image inside the td/layer. I keep getting 'undefined'. I've tried document.layers["snBG"].document.images["label"], document.layers["snBG"].document.images[0], document.images["label"], etc. If I remove the relative class from the td, it no longer converts to a layer and I can access the image just fine in the normal manner. It's only when it is converted into a layer. Any ideas?

bisqui
01-18-2003, 05:26 PM
yeah, this is in NS4. Otherwise I could just access the background image with getElementsByTagName and avoid having to convert it to a layer. This is how I'm handling it in IE and NS6

bisqui
01-18-2003, 06:23 PM
I tried changing it to absolute positioning just to see if it made any difference. No luck. Any other suggestions? I could always have a seperate file or do a document.write for NS4 but I'd rather avoid that.

gil davis
01-18-2003, 07:14 PM
Perhaps there is an aparently unrelated error in the "extraneous tags".

This works:
<head>
<style type="text/css">
.rel {position: relative; background-image: url("lilguy2.gif")}
</style>
</head>
<body>
<table>
<tr>
<td id="td1" class="rel">
<table>
<tr>
<td><img name="i1" src="cancel.gif"></td>
</tr>
</table>
</td></tr>
</table>
<a href="#" onclick="document.td1.background.src='bookmark.gif';return false">change bgImage</a><br>
<a href="#" onclick="alert(document.td1.document.i1.src);return false">reveal img src</a>
</body>

bisqui
01-19-2003, 10:12 AM
Hmmm, yeah, I must have a mistake somewhere else then. I'll post if I can find it. I'm just going to step away from this for a bit and come back later. Hopefully the error will be obvious then. Thanks for the help.

bisqui
01-19-2003, 11:32 AM
yep, you were right. the problem was in the tags I left out. The table with the relative td is actually nested in another table. For some reason, it doesn't like that. Once I took it out of the nested table, everything worked fine. Thanks again for the help.