Solved

javascript/table spacing and Firefox problem

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iOS retina Display, HTML Email Signature 5 525
Programatically edit Web.config 8 37
Migrating to Exchange 2013 4 48
jQuery Date picker not working 16 182
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…
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.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 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