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!

divs work in IE6 but not in FF

Status
Not open for further replies.

lastdonuk

Programmer
Jan 19, 2005
58
GB
Hi,

I've inherited a website which is causing me a particular problem by not functioning correctly in firefox.
As an experiment, I recreated the problem code in Dreamweaver MX using the design view to see how IE6 & Firefox 1.0.4 handled it. IE works fine - it's 3 radio buttons each showing a layer on click of the corresponding button, the page is here:

div.htm

However, this code does not function in FF, I'm wondering if it's some problem with the javascript setting the layers to be visible/invisible? The code is here:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Layers - crossbrowser</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if 

((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; 

onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) 

location.reload();
}
MM_reloadPage(true);

function setvisible(Layer)
{
appname = navigator.appName;

	if (appname == "Microsoft Internet Explorer")
	{
		Layer.style.visibility = "visible";
	}
	else
	{
		setinvisible(Layer);
		Layer.visibility = true; 
	}
}

function setinvisible(Layer) 
{
appname = navigator.appName;
	if (appname == "Microsoft Internet Explorer")
	{
		Layer.style.visibility = "hidden";
	}
	else
	{
		setinvisible(Layer);
		Layer.visibility = false;
	}
}

//-->
</script>
</head>
<body>
<form name="form1" method="post" action="">
  <p> 
    <label> 
    <input type="radio" name="r1" value="noadv" 

onClick="setvisible(Layer1);setinvisible(Layer2);setinvisible(Layer3)">
    option 1</label>
    <br>
    <label> 
    <input type="radio" name="r1" value="advref" 

onClick="setvisible(Layer2);setinvisible(Layer1);setinvisible(Layer3)">
    option 2</label>
    <br>
    <label> 
    <input type="radio" name="r1" value="broker" 

onClick="setvisible(Layer3);setinvisible(Layer2);setinvisible(Layer1)">
    option 3</label>
    <br>
  </p>
  <div id="Layer1" style="position:absolute; width:200px; height:115px; 

z-index:1; left: 154px; top: 19px; visibility: hidden;"> 
    <div align="center">1</div>
  </div>
  <div id="Layer2" style="position:absolute; width:200px; height:115px; 

z-index:2; left: 156px; top: 21px; visibility: hidden;"> 
  	<div align="center">2</div>
  </div>
  <div id="Layer3" style="position:absolute; width:200px; height:115px; 

z-index:3; left: 155px; top: 22px; visibility: hidden;">
    <div align="center">3</div>
  </div>
  <p>&nbsp; </p>
</form>
</body>
</html>

I've read alot of generalities about the problems with divs in FF, but can't work out which aspect of the code is the issue. I've posted this on a couple of the forums as I'm not sure as to the exact issue. Any pointers in the right direction here would be greatly appreciated.

Thanks.
 
This is a problem to do with the IE-only shortcuts you've used to refer to your elements when passing the parameters (Layer1, Layer2, etc).

You should use document.getElementById - as it is cross-browser.

If you need more help, I'd ask in the JavaScript forum (forum216).

Hope this helps,
Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Thanks for your advice Dan, I'll do what you suggest.
 
Thanks for your help Dan, you fixed it! (in the javascript forum).I also got one other excellent suggestion for this, and both can be viewed at thread216-1065490.
Many thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top