Solved

javascript/table spacing and Firefox problem

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now