PDA

View Full Version : innerHTML in NS4.75...


Candyass
09-24-2002, 07:37 AM
OK I give up :)

Is there any way to use innerHTML in NS4.75, or some other way to accomplish the same as I do in IE with the code below?

I just want to replace the content in a <div></div> based on the parameter passed to the function. Here's my IE code:

function ShoworNot(mama)
{
var str = "";
oOpt = document.all("imageSwap");
if(mama==1)
{
str = "<TABLE cellpadding='0' cellspacing='0' border='0' height='100%'>"
str += "<TR><TD background='bodybg1.gif'><img src='clear.gif'></TD></TR>"
str += "<TR><TD height='7' valign='top'><img src='bodybtm1.gif' height='7'></TD></TR>"
str += "</TABLE>"
oOpt.innerHTML = str
}
else if(mama==2)
{
str = "<TABLE cellpadding='0' cellspacing='0' border='0' height='100%'>"
str += "<TR><TD background='bodybg2.gif'><img src='clear.gif'></TD></TR>"
str += "<TR><TD height='7' valign='top'><img src='bodybtm2.gif' height='7'></TD></TR>"
str += "</TABLE>"
oOpt.innerHTML = str
}
}
---------------------------------------- then the body......
<BODY onLoad="ShoworNot('1')"
<form name="hi">
<TABLE>
<TR>
<TD background="clear.gif" valign="bottom">
<div id="imageSwap">a</div>
</TD>
</TR>
</TABLE>
</form>
</BODY>

Thanks (and nice to see you guys are still around!)

Matz

glenngv
09-24-2002, 08:01 AM
you have to use <layer> tag for NS4.X

<TD background="clear.gif" valign="bottom">
<div id="imageSwap">a</div><layer id="imageSwapNS"></layer>
</TD>

then in your function:

function ShoworNot(mama)
{
var str = "";
if (document.all) oOpt = document.all["imageSwap"];
else if (document.getElementById) oOpt = document.getElementById("imageSwap");
else if (document.layers) oOpt = document.layers["imageSwapNS"];
else {
alert("Please use IE or Netscape.");
return;
}
if(mama==1)
{
str = "<TABLE cellpadding='0' cellspacing='0' border='0' height='100%'>"
str += "<TR><TD background='bodybg1.gif'><img src='clear.gif'></TD></TR>"
str += "<TR><TD height='7' valign='top'><img src='bodybtm1.gif' height='7'></TD></TR>"
str += "</TABLE>"
if (document.all || document.getElementById) oOpt.innerHTML = str
else {oOpt.document.write(str);oOpt.document.close();}
}
else if(mama==2)
{
str = "<TABLE cellpadding='0' cellspacing='0' border='0' height='100%'>"
str += "<TR><TD background='bodybg2.gif'><img src='clear.gif'></TD></TR>"
str += "<TR><TD height='7' valign='top'><img src='bodybtm2.gif' height='7'></TD></TR>"
str += "</TABLE>"
if (document.all || document.getElementById) oOpt.innerHTML = str
else {oOpt.document.write(str);oOpt.document.close();}
}
}

glenngv
09-24-2002, 08:10 AM
...or simply this!

<BODY onLoad="ShoworNot(1)">
<form name="hi">
<TABLE>
<TR>
<TD background="clear.gif" valign="bottom">

<TABLE cellpadding='0' cellspacing='0' border='0' height='100%'>
<TR><TD background='bodybg2.gif'><img src='clear.gif'></TD></TR>
<TR><TD height='7' valign='top'><img name='img' src='bodybtm1.gif' height='7'></TD></TR>
</TABLE>

</TD>
</TR>
</TABLE>
</form>
</BODY>

function ShoworNot(mama)
{
if (mama==1) document.images["img"].src="bodybtm1.gif";
else if (mama==2) document.images["img"].src="bodybtm2.gif";
}


...since you are only changing the image src.
that way you don't have to bother what browser the user is using.
btw, in your function, mama is an integer but when you call it, you pass a string. you have to make it the same data type.

Candyass
09-24-2002, 08:28 AM
Aaah - that looks like the best solution, but I'm also changing the background='bodybg2.gif' as well. I tried putting a name (tried an ID as well) on the TD to change the background image but no luck. Can this be done? If it can be done it would be too cool!

Thanks for helping out!

Matz

glenngv
09-24-2002, 09:26 AM
<TABLE cellpadding='0' cellspacing='0' border='0' height='100%'>
<TR><TD id="td" background='bodybg2.gif'><img src='clear.gif'></TD></TR>
<TR><TD height='7' valign='top'><img name='img' src='bodybtm1.gif' height='7'></TD></TR>
</TABLE>


function ShoworNot(mama)
{
if (mama==1) {
document.images["img"].src="bodybtm1.gif";
if (document.getElementById) document.getElementById("td").style.backgroundImage="bodybg1.gif";
else if (document.all) document.all["td"].style.backgroundImage="bodybg1.gif";
}
else if (mama==2) {
document.images["img"].src="bodybtm2.gif";
if (document.getElementById) document.getElementById("td").style.backgroundImage="bodybg2.gif";
else if (document.all) document.all["td"].style.backgroundImage="bodybg2.gif";
}
}


note that background image for TD only works with IE and NS6.X, not with NS4.X

Candyass
09-24-2002, 04:13 PM
Thank you Glenn for all your angles!. I tried a similar thing as in your last example last night - using getElementById, but the main bummer is that I want to make it work in NS4 :(

I guess you can't have it all huh? :)

Thanks again!

Matz