It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

doctype & getElementById in Firefox

doctype & getElementById in Firefox

Postby jbunnell on Fri Apr 11, 2008 5:09 am

I am having a problem with my javascript functions that display pop-up menus on mouse rollover which use document.getElementById(). The page views perfectly in IE with the doctype, and perfectly in Firefox without the doctype. What do I need to do to my code to make this work right in both browsers including the doctype?

These are the functions that take care of displaying and removing that popup menus:

var menus = new Array(3);
menus = ['maintenance', 'rudiments', 'percussion'];
function showMenu(id){
clearMenus();
document.getElementById(id).style.zIndex="1";
}
function removeMenu(id){
document.getElementById(id).style.zIndex="-1";
}
function clearMenus(){
for(var i=0; i<menus.length; i++){
var menu = document.getElementById(menus[i]);
if(menu.style.zIndex=="1"){
removeMenu(menus[i]);
}
}
}


In my html document, I am using:

<!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" xml:lang="en" lang="en">

This works perfectly in IE, but in Firefox the popup menus don't display. When I remove the doctype, it works perfectly in Firefox, but completely throws everything off in IE. Firefox debugger says that every time getElementById() is called it has no properties, although I know my id names are correct on my div tags in my html document. How do I fix this?
jbunnell
 
Posts: 3
Joined: Fri Apr 11, 2008 4:53 am

Postby rangana on Fri Apr 11, 2008 6:51 am

Can we see the rest of the code...or even a snippet that would reproduce this problem ;)

...We're unaware what id could accept in showMenu function :)
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Postby jbunnell on Sat Apr 12, 2008 1:51 am

This is 'jsFunction.js':

<!-------The functions showMenu() and removeMenu() are used to display the pop-up menus on the navigation bar----------->
var menus = new Array(3);
menus = ["maintenance", "rudiments", "percussion"];
function showMenu(id){
clearMenus();
document.getElementById(id).style.zIndex="1";
}
function removeMenu(id){
document.getElementById(id).style.zIndex="-1";
}
function clearMenus(){
for(var i=0; i<menus.length; i++){
var menu = document.getElementById(menus[i]);
if(menu.style.zIndex=="1"){
removeMenu(menus[i]);
}
}
}

<!-----underline() and removeUnderline() are used to display the rollover on the navigation bar----------->
function underline(id){
document.getElementById(id).style.textDecoration="underline";
}
function removeUnderline(id){
document.getElementById(id).style.textDecoration="none";
}

<!------highlight() and unhighlight() are used to display the rollover on the pop-up menus-------------->
function highlight(cellId, fontId){
document.getElementById(cellId).style.backgroundColor="#ffff99";
document.getElementById(fontId).style.color="black";
}
function unhighlight(cellId, fontId){
document.getElementById(cellId).style.backgroundColor="green";
document.getElementById(fontId).style.color="#ffff99";
}





Here is my html document:

<!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" xml:lang="en" lang="en">
<head>
<link href="styles.css" rel="stylesheet" type="text/css">
<script src="jsFunctions.js" language="javascript" type="text/javascript"></script>
</head>

<body>

<!----------Body which contains the content of the page--------------->
<div id="content" class="content" onmousedown="clearMenus();" onmouseup="clearMenus();">
<h1>Choosing Your Drum Kit</h1>
</div>

<!-----Menu for Tuning & Maintenance--------------------->
<div id="maintenance" class="maintenance">
<table align="left" border="0" cellpadding="2" cellspacing="1" bgcolor="green">
<tr><td id="m1" onmouseover="highlight('m1', 'mf1');" onmouseout="unhighlight('m1', 'mf1');">
<a href=""><font id="mf1">tuning</font></a></td>
</tr>
<tr><td id="m2" onmouseover="highlight('m2', 'mf2');" onmouseout="unhighlight('m2', 'mf2');">
<a href=""><font id="mf2">set up your kit</font></a></td>
</tr>
<tr><td id="m3" onmouseover="highlight('m3', 'mf3');" onmouseout="unhighlight('m3', 'mf3');">
<a href=""><font id="mf3">prepare</font></a></td>
</tr>
<tr>
<td height="85"></td>
</tr>
</table>
</div>

<!-------Menu for Rudiments & Drum Beats----------------->
<div id="rudiments" class="rudiments">
<table align="left" border="0" cellpadding="2" cellspacing="1" bgcolor="green">
<tr>
<td id="r1" onmouseover="highlight('r1', 'rf1');" onmouseout="unhighlight('r1', 'rf1');">
<a href=""><font id="rf1">Advanced</font></a>
</td>
</tr>
<tr>
<td id="r2" onmouseover="highlight('r2', 'rf2');" onmouseout="unhighlight('r2', 'rf2');">
<a href=""><font id="rf2">Intermediate</font></a>
</td>
</tr>
<tr>
<td id="r3" onmouseover="highlight('r3', 'rf3');" onmouseout="unhighlight('r3', 'rf3');">
<a href=""><font id="rf3">Beginner</font></a>
</td>
</tr>
<tr>
<td height="85"></td>
</tr>
</table>
</div>

<!------------Menu for Auxiliary Percussion----------------------->
<div id="percussion" class="percussion">
<table align="left" border="0" cellpadding="2" cellspacing="1" bgcolor="green">
<tr>
<td id="p1" onmouseover="highlight('p1', 'pf1');" onmouseout="unhighlight('p1', 'pf1');">
<a href="aux/bells.html"><font id="pf1">bells & xylos</font></a>
</td>
</tr>
<tr>
<td id="p2" onmouseover="highlight('p2', 'pf2');" onmouseout="unhighlight('p2', 'pf2');">
<a href="aux/concertstuff.html"><font id="pf2">concert stuff</font></a>
</td>
</tr>
<tr>
<td id="p3" onmouseover="highlight('p3', 'pf3');" onmouseout="unhighlight('p3', 'pf3');">
<a href="aux/beginner.html"><font id="pf3">Beginner</font></a>
</td>
</tr>
<tr>
<td height="85"></td>
</tr>
</table>
</div>

<!-------------Footer which contains the Navigation Bar--------------->
<div class="foot">
<hr>
<table width="700">
<tr align="center">
<td><a href="choose.html" name="choose"
onmouseover="underline('choose');clearMenus();"
onmouseout="removeUnderline('choose');">
<font id="choose">Choosing a Drum Kit</font></a>
</td>
<td><a href="maintenance.html" name="maintenance"
onmouseover="underline('tuning');showMenu('maintenance');"
onmouseout="removeUnderline('tuning');">
<font id="tuning">Tuning & Maintenance</font></a>
</td>
<td><a href="technique.html" name="technique"
onmouseover="underline('technique');clearMenus();"
onmouseout="removeUnderline('technique');">
<font id="technique">Proper Sticking & Technique</font></a>
</td>
<td><a href="rudiments.html" name="rudiments"
onmouseover="underline('beats');showMenu('rudiments');"
onmouseout="removeUnderline('beats');">
<font id="beats">Rudiments & Drum Beats</font></a>
</td>
<td><a href="percussion.html" name="percussion"
onmouseover="underline('aux');showMenu('percussion');"
onmouseout="removeUnderline('aux');">
<font id="aux">Auxiliary Percussion</font></a>
</td>
<td><a href="expand.html" name="expand"
onmouseover="underline('expand');clearMenus();"
onmouseout="removeUnderline('expand');">
<font id="expand">Expand Your Style</font></a>
</td>
</tr>
</table>
<hr>
<div>

</body>
</html>




Here is my css file:

.content{
position:absolute;
top:0px;
left:0px;
bottom:88px;
background-color:#ffff99;
width:100%;
z-index:0;
overflow:auto;
}
.maintenance{
font:9pt "Arial";
position:fixed;
left:125px;
bottom:0px;
z-index:-1;
}
.rudiments{
font:9pt "Arial";
position:fixed;
left:385px;
bottom:0px;
z-index:-100;
}
.percussion{
font:9pt "Arial";
position:fixed;
left:507px;
bottom:0px;
z-index:-100;
}
.foot {
position:fixed;
left:0px;
bottom:0px;
padding:0;
border-top:1;
background-color:green;
width:100%;
height:88px;
z-index:2;
}
a:link{
font:11pt "Arial";
text-decoration:none;
color:#ffff99;
}
a:visited {
font:11pt "Arial";
text-decoration:none;
color:#ffff99;
}
a:active {
font:11pt "Arial";
color:#00ff33;
}
jbunnell
 
Posts: 3
Joined: Fri Apr 11, 2008 4:53 am

Postby rangana on Sat Apr 12, 2008 2:10 am

For future reference, next time, do place your codes inside the [code] [/ code] tag of this forum...;)

...Anyway, I don't know what you are trying to achieve, See this line:
[code]
function clearMenus(){
for(var i=0; i<menus.length; i++){
var menu = document.getElementById(menus[i]);
if(menu.style.zIndex=="1"){
removeMenu(menus[i]);
}
}
}

[/code]

...This is a complete error. I don't understand what menus are you referring :(

...Also you might find it useful to get firebug...It makes us (web developer) easy to find the error ;)

Hope that makes sense ;)
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Postby jbunnell on Sat Apr 12, 2008 2:29 am

menus is a string array that is set up at the very beginning of the javascript file... it contains 3 strings, each of which are the ids for my div tags that contain the popup menus. All clearMenus() does is setup a loop to go through and check whether each popup menu has a z-index of 1, and if so changes it to -1. I am positive that my javascript is correct... the entire rollover on everything works fine in firefox until I add in the doctype, then it says that getElementById has no properties every time it is called.
jbunnell
 
Posts: 3
Joined: Fri Apr 11, 2008 4:53 am

Postby rangana on Sat Apr 12, 2008 2:45 am

Yeah, my apologies, This is weird, you're right, the DTD creates the conflicts.

...Have you given it a try to change the DTD's?..

I also have the same problem with one of my scripts not working when the page has had DTD..but i'm certain this is not the same as yours, because I'm using ilayer on mine ;)

...Anyway, this is'nt an intelligent suggestion, but give it a try changing DTD's. See which of which works on your script.

...All I could say is that this is a complete weird :)
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines


Who is online

Users browsing this forum: No registered users and 4 guests