Forum Moderators: open

Message Too Old, No Replies

Javascript is working with IE7 and Safari, but wont work with Firefox

         

tarasbaida

6:25 am on Jul 4, 2008 (gmt 0)

10+ Year Member



Hello,

Here is the code


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>...</title>
<link href="main.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
function showSub(id)
{
var el = document.getElementById(id);
if ( el.style.display != "none" )
{
el.style.display = "none";
}
else
{
secondmenuservices.style.display = "none";
secondmenuread.style.display = "none";
secondmenuabout.style.display = "none";
secondmenucontact.style.display = "none";
el.style.display = "";
}
}
</script>

</head>

Then I have a table cell with <a> in it, which is using that script onclick


<div id="mainmenu">
<table cellpadding="0px" cellspacing="0px" border="0px" width="100%" height="100%">
<td width="100%">
<a href="#" onclick="showSub('secondmenuservices')" class="nava">Button</a>
</td>
</table>
</div>

When clicked, it should show the table with id="secondmenuservices" and style display:none, when clicked again - hide it. Here it is.


<table id="secondmenuabout" cellpadding="0px" cellspacing="0px" border="0px" width="100%" height="100%" style="display:none; padding-left:20px">
<td>
<a href="123/123t.html" class="navb">О компании</a>
<a href="#" class="navb">123</a>
</td>
</table>

As I said, it works in ie7 and safari, but not in firefox, what can be done?

Thanks.

tarasbaida

6:28 am on Jul 4, 2008 (gmt 0)

10+ Year Member



/note
the table in the third part of code has ID "secondmenuabout" instead of "secondmenuservices", but thats _not_ the problem, just copied wrong part of code from my html file.

torbol

6:37 am on Jul 4, 2008 (gmt 0)

10+ Year Member



secondmenuservices.style.display = "none";
secondmenuread.style.display = "none";
secondmenuabout.style.display = "none";
secondmenucontact.style.display = "none";

secondmenuservices, secondmenuread, secondmenuabout, secondmenucontact are no references. You need a handles for every one like:

secondmenuread = document.getElementById('id_name');

Other way it can't work

tarasbaida

7:00 am on Jul 4, 2008 (gmt 0)

10+ Year Member



torbol, thanks for your answer.

Could you please be a bit more specific on this, should I just write document.getElementById('secondmenuservices').style.display="none" instead of secondmenuservices.style.display = "none"?
Im new to javascript.

daveVk

7:01 am on Jul 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



TRY

function showSub(id)
{
var el = document.getElementById(id);
if ( el.style.display != "none" ) { el.style.display = "none"; }
else { el.style.display = "block"; }
}

tarasbaida

9:33 am on Jul 4, 2008 (gmt 0)

10+ Year Member



ok its working, everyone tyvm