PDA

View Full Version : Netscape 6.0 DOM div visibility


joc
12-04-2002, 07:05 PM
Hi,

I'm having problems controlling the visibility of a layer (div).

I can only get the layer to appear when I use the layerID explicitly, i.e. "layerBook", but I can't stick the name into a var, i.e. var layerName = "layerBook" doesn't work.

-------------------------------------------------------
Here's the snippet of code:

var sTypeOptions = ["JournalArticle", "Book", "Manuscript"];

function changeField(selectvalue) {
var layerName = "layer" + selectvalue;
var layerNameNet6 = "\'" + layerName + "\'";

for (i=0;i<sTypeOptions.length;i++) {
var thisLayer = "layer" + sTypeOptions[i];
var thisLayerNet6 = "\"" + thisLayer + "\"";

if (selectvalue==sTypeOptions[i]) {
if (document.getElementById&&!document.all) {
//THE FIRST 2 LINES HERE DON'T WORK
//document.getElementById(layerName).style.visibility = "visible";
//document.getElementById(layerNameNet6).style.visibility = "visible";
document.getElementById("layerBook").style.visibility = "visible";
} //if
}//if

else {
//make the other layers hidden
if (document.getElementById&&!document.all) {
document.getElementById(thisLayer).style.visibility = "hidden";
} //if
} //else
} //for

} //changeField

//document.getElementById(layerName).style.visibility = "visible"; //document.getElementById(layerName).style.visibility = "visible";

beetle
12-04-2002, 08:02 PM
Are you sure selectvalue is receiving a proper value?

Adding the " or ' for Netscape6 is unecessary, so you can remove all the duplicitous code that revolves around it.

What are you doing with the vars thisLayer and thisLayerNet6? You declare them but never use them. I suspect that you mean to use them in the two commented-out lines, which probably explains why they don't work.

joc
12-04-2002, 08:29 PM
The point I was trying to make is that I would like to use this line of code:

document.getElementById(layerName).style.visibility = "visible";

but for some reason, it doesn't work.

I know the layerName is being constructed correctly, since the full version of my code (which I did not post) works in IE and Netscape 4. It's just the getElementById part that doesn't recognize layerName or thisLayer.

beetle
12-04-2002, 08:37 PM
Nothing wrong with doing that in NS6. It must be something else.

glenngv
12-05-2002, 01:45 AM
as beetle said, adding ' or " in layer name is not needed.

var layerName = "layer" + selectvalue;
//var layerNameNet6 = "'" + layerName + "'"; //not needed

document.getElementById(layerName).style.visibility = "visible";


var thisLayer = "layer" + sTypeOptions[i];
//var thisLayerNet6 = "\"" + thisLayer + "\""; //not needed

document.getElementById(thisLayer).style.visibility = "hidden";