...

View Full Version : why can't I change the bgcolor in a layer?



jeepzy3
07-08-2002, 06:45 PM
I have the following simple script. I can make the layer hide & show, but I can't seem to change the bgcolor. When I throw the 1st alert(xLayer.bgcolor) I get undefined. The next time I display xLayer.bgcolor, I get "blue"

<HTML>
<HEAD><SCRIPT src=/javascript/special.js>

</SCRIPT>
<SCRIPT>
function chg(color)
{
var xLayer=document.layers["mgt_layer2"];
alert(xLayer.bgcolor); //get undefined
//xLayer.bgcolor="blue";
xLayer.bgcolor=color
//xLayer.visibility="hide";
alert(xLayer.id); //get mgt_layer2
alert(xLayer.bgcolor); //get blue
return true
}
</SCRIPT>
</HEAD><BODY BGCOLOR='FFFFFF' TEXT='000000' ALINK=WHITE VLINK=WHITE LINK=WHITE>
<FORM NAME=emp_form METHOD=POST>
<TABLE CELLPADDING=0 CELLSPACING=0>
<TR><TH><FONT FACE=ARIAL SIZE=2>Organization Code:
<TD ALIGN=CENTER><FONT FACE=ARIAL SIZE=2>
<INPUT TYPE="TEXT" NAME="org_code2" VALUE="" READONLY MAXLENGTH=25 SIZE=25 >
<TR><TH><FONT FACE=ARIAL SIZE=2>Segment Code:<TH>
<SELECT NAME=seg SIZE=4>
<OPTION VALUE=1A2000000 ><FONT FACE=ARIAL SIZE=2>0000</FONT></OPTION>
<OPTION VALUE=1A2300000 ><FONT FACE=ARIAL SIZE=2>Z000</FONT></OPTION>
<OPTION VALUE=1A230A000 ><FONT FACE=ARIAL SIZE=2>A000</FONT></OPTION>
<OPTION VALUE=1A230E000 ><FONT FACE=ARIAL SIZE=2>E000</FONT></OPTION>
<OPTION VALUE=1A230F000 ><FONT FACE=ARIAL SIZE=2>F000</FONT></OPTION>
<OPTION VALUE=1A230K000 ><FONT FACE=ARIAL SIZE=2>K000</FONT></OPTION>
<OPTION VALUE=1A230N000 ><FONT FACE=ARIAL SIZE=2>N000</FONT></OPTION>
</SELECT>
<TH><INPUT TYPE=BUTTON value=GO>
<TR><TD>
Management: <input name="management" type="radio" value="yes" onclick="chg('blue')"> <strong> yes
<input name="management" type="radio" value="no" onclick=" document.mgt_layer3.visibility='hide'"> no </strong>
</TABLE>
</FORM>
<BR><BR>
<LAYER name=mgt_layer2 bgcolor="yellow">Text inside layer 2 </LAYER><BR>
<LAYER id=mgt_layer3>Text inside layer 3 </LAYER>
</HTML>

A1ien51
07-08-2002, 06:51 PM
you forgot style


it goes.........style.background="#808080"

jeepzy3
07-08-2002, 08:51 PM
I tried the following, but it still didn't work for me.

xLayer.style.background="#808080";

adios
07-08-2002, 09:01 PM
Layer.bgColor

[case-sensitive]

Also: use id for NS4 layers, it's supported. No .style object in Navigator.

jeepzy3
07-08-2002, 09:15 PM
I changed name back to id within the layer tag. I had it this way originally, but it didn't work.

I'm not sure how what you mean by using Layer.bgColor. How do you differentiate between the two layers mgt_layer2, mgt_layer3?

function chg(color)
{
var xLayer=document.Layer["mgt_layer2"];
xLayer.bgColor=color

return true
}

adios
07-08-2002, 09:24 PM
function chg_bgColor(id, color)
{
if (document[id]) document[id].bgColor = color;
}

Might as well make it more flexible (instead of hardcoding in the layer id). All named/id'd layers can be referenced as document properties, no need to go through the .layers[] collection.

Layer.bgColor...Layer here is a generalization, representing the Layer class of objects; in actual use, you'd replace it with an actual layer reference.

jeepzy3
07-08-2002, 09:37 PM
Thanks again! That worked like a charm.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum