PDA

View Full Version : Problem with making a hidden layer visible in Firefox



jcfra420
05-09-2007, 03:58 PM
I am using the following script to hide/unhide a layer in a site that I am building:


function hidediv() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('form1POP').style.visibility = 'hidden';
}
else {
if (document.layers) { // Netscape 4
document.hideShow.visibility = 'hidden';
}
else { // IE 4
document.all.hideShow.style.visibility = 'hidden';
}
}
}

function showdiv() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('form1POP').style.visibility = 'visible';
}
else {
if (document.layers) { // Netscape 4
document.hideShow.visibility = 'visible';
}
else { // IE 4
document.all.hideShow.style.visibility = 'visible';
}
}
}

It works perfectly in IE6, IE7, and Opera (though in Opera the opacity isn't working but that is fine) But when I click on the button using Firefox the layer does not become visible. Can anyone help me out, this is on a short deadline...

Many thanks

JF

Twey
05-09-2007, 04:10 PM
function showElement(id, w) {
(document.getElementById(id) || document.all[id]).style.visibility = ((typeof w !== "undefined" && !w) ? "hidden" : "");
}Usage:
showElement("form1POP", false); // Hide form1POP
showElement("form1POP"); // Show form1POP

jcfra420
05-10-2007, 06:53 PM
Thanks for the reply Twey, I placed the script you provided in my .js file, and added the function info you placed underneath for the link:


javascript:showElement('form1POP');

but when I test it, it doesn't open the window in Firefox or IE. Any suggestions? I placed the button code below so you can see the whole thing.


<a href="javascript:showElement('form1POP');">contact</a>

The css style of the pop up is set to hidden originally, do I have to remove that using this script? Does the script hide the layer ( ie onload?)

Thanks

JF

Twey
05-10-2007, 07:19 PM
The css style of the pop up is set to hidden originally, do I have to remove that using this script?Yes. It shouldn't be hidden originally anyway: non-Javascript users won't be able to see it.
Does the script hide the layer ( ie onload?)No, but it's easy enough to do if you want to:
window.onload = function() {
showElement("form1POP", false);
};