Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript firefox problem

Status
Not open for further replies.

yshaf13

Programmer
Jun 16, 2007
2
US
hi i have this script wich works exactly as expected in ie but in firefox it gets a little bit messed up. here is the script:
Code:

HTML Code:

<script language="JavaScript"> function show(obj) { document.getElementById(obj).style.display = (document.getElementById(obj).style.display=='block') ? 'none':'block'; } </script> </head> <body bgcolor="#ffffff"> <form id="FormName" action="(EmptyReference!)" method="get" name="FormName"> <table width="470" border="1" cellspacing="2" cellpadding="0"> <tr> <td><label>First Name</label></td> <td><input type="text" name="first" size="24" /></td> </tr> <tr id="a" style="display:none"> <td><label>Phone Number 2</label></td> <td><input type="text" name="phone2" size="24" /></td> </tr> <tr><td><input type="button" onclick="show('a')" value="Add Number"></td><td> add #</td></tr> </table> </form> <p></p> </body> </html>

In firefox it bunches up the whole row in the space of the first <td>.
What do i do? is there a way to get around this?
Reply With Quote
 
[tt]<tr>[/tt] elements are not "block" by default. instead of setting the display to "block", try setting to an empty string:

Code:
function show(obj) { 
    document.getElementById(obj).style.display = (document.getElementById(obj).style.display=='') ? 'none':'';
}

and in the future, why not try line breaks and indentations? they do a world of good.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Cory's right, firefox won't display them correctly if you try to set them to block. Their proper display type is table-row, which IE won't understand - so you're better off using Cory's explanation of setting it to an empty string - which is basically the same as saying "set it back to default".

Hey Cory, SW FTW you sexy beast!

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
YAYYYY!!!!

word is born.

headbang.gif




*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top