Solved

javascript/table spacing and Firefox problem

Posted on 2004-08-14
5
1,606 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
  • 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

777 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