Solved

javascript/table spacing and Firefox problem

Posted on 2004-08-14
5
1,610 Views
Last Modified: 2010-04-06
I have this little javascript working that expands the table rows to show submenus.  My problem is that it really screws up the spacing in Firefox.  Works Great in IE.

Any help would be appreciated.

<script type="text/JavaScript">
function togglemenu(submenu)
{
     obj = document.getElementsByTagName('tr');
        for (i=0; i<obj.length; i++)
     {
          if (obj[i].id == submenu)
                    if (obj[i].style.display == 'none')
                      obj[i].style.display = 'block';
                  else obj[i].style.display = 'none';
     }
     
}
//-->
</script>

<table style="width: 100%;"  border="0" cellpadding="0" cellspacing="0" class="menu_background">
                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td width="1%">&nbsp;</td>
                  <td width="99%"><a href="#" onClick="togglemenu( 'menu1' );" onKeyPress="togglemenu( 'menu1' );">Membership</a> </td>
                </tr>
                <tr id="menu1" style="display: none;">
                  <td>&nbsp;</td>
                  <td nowrap>submenu 1</td>
                </tr>
                <tr id="menu1" style="display: none;">
                  <td>&nbsp;</td>
                  <td nowrap>submenu 2</td>
                </tr>

                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td colspan="2"><img name="banner1_r6_c1" src="images/banner1_r6_c1.jpg" width="121" height="15" border="0" alt=""></td>
                </tr>
</table>
0
Comment
Question by:rockmansattic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 31

Accepted Solution

by:
seanpowell earned 300 total points
ID: 11800952
Try this instead - just leaving the display blank, instead of block

if (obj[i].id == submenu)
   if (obj[i].style.display == 'none')
   obj[i].style.display = '';
   else obj[i].style.display = 'none';
0
 
LVL 53

Assisted Solution

by:COBOLdinosaur
COBOLdinosaur earned 200 total points
ID: 11800974
IE does not have much respect for the table objects, so it let's you do all kinds of stuff with them that will mess up the DOM on a standards compliant browser.  Try this way:
if (obj[i].id == submenu)
    if (obj[i].style.display == 'none')
       obj[i].style.display=(document.all)? 'block' : 'table-row';
    else obj[i].style.display = 'none';

Cd&
0
 
LVL 10

Author Comment

by:rockmansattic
ID: 11802247
Thank you both, SeanPowell's comment works and it was first..

Just deciding whether or not to split points??  

COBAL>>Is the =(document.all)? 'block' : 'table-row'; nessicary??
For what reason..

Thanks again.

Rockman
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 11802286
Within the standards, the correct display is table-row.  Using display='' cause default display behaviour but there is no guarantee that default behaviour in the future will be the same cross-browser because MS has move away from strong support of teh complex table model in the dom, in favour of the activex driven databinding that it makes to make .net viable.

I have always figured that if you declare things to be what the are you will get fewer nasty surprises as browsers and other software slowly mirgrate to hager levels of standards compliance.

Cd&
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 11804085
Glad we could help.  Thanks for the A... and fo rmaking me number one in the Topic. :^)

Cd&
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question