Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide div. works in IE and Opera but not Firefox ? 1

Status
Not open for further replies.

CoffeeQuick

Programmer
Jul 6, 2004
23
0
0
GB
I have a web page that has 3 maps each in a separate div hidden off the side of the page. When you click a button the chosen map then scrolls into view.
This part of the code works fine in IE, Opera and Firefox, but when it comes to hide the maps again, the script to hide doesn't work in Firefox (works fine on IE and Opera).

This is the script to show a map.

Code:
function showMap1() {
	hiddenLayer = document.getElementById("map1");
	layerPosition = parseInt(hiddenLayer.style.left);
	if (layerPosition < 0) {
		hiddenLayer.style.left = (layerPosition + 2) + "px";
		setTimeout("showMap1()", 5);
		}
	}

And this is the script to hide the map

Code:
function hideLayer(Tablayer, dis) {
	Tablayer.style.left = dis + "px";
}

There is a separate script to show each map, but a generic one to hide the maps. I have tried putting a document.getElementById("map1") command into the hide script, instead of passing the div id as a variable, but this makes no difference.

Can anyone see why this is happening, and suggest a fix that will work in all 3 browsers.

Thanks.

John
 
How are you calling the function?
What is the value of dis?
What is the value of Tablayer?
What is the initial value set to the left property?

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
The function is called using the following

Code:
<a href="javascript:hideLayer(map1, -499);" class="small">&lt;&lt;Hide Map 1 / </a>

The value of dis is the width of the map as negative number to move it off the side of the page.

The value of Tablayer is the ID of the div eg. "map1"

The initial value of the left property is 0 when the map is displayed.

Thanks for looking into this.

John
 
it could be that "style.left" is not set initially...try

layerPosition = parseInt(hiddenLayer.offsetLeft);



=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 
You're effectively trying to pass an undefined variable (called map1) to the hideLayer() function (as far as Firefox is concerned).

You need to either pass document.getElementById( "map1" ); (the element itself) or pass it as a string (hideLayer('map1', -499);) and then use document.getElementById( Tablayer ).style etc within the hideLayer() function.

HTH.

 
Thanks for the help everyone especially theboyhope,

Changed the code to pass the layer id as a string, and added the document.getElementById(Tablayer) within the hideLayer() function, and it now works in all 3 browsers.

Thanks again

John [atom]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top