Show hide row in netscape using javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Abraham

    Show hide row in netscape using javascript

    Hi,

    The following code to show and hide a row works fine in netscape 7 and
    IE 6. But everytime the cell is hidden and displayed in netscape, it
    adds a new line inside the cell. Please advise.
    ----snip----
    <html>
    <head>
    <title>Table hide</title>
    <script language="javas cript">
    function flipCell(count) {
    f=document.getE lementById("mce ll");
    f.style.display =(f.style.displ ay=="block")?"n one":"block";
    }
    </script>
    </head>
    <body>
    <a href="javascrip t:flipCell(0)"> here</a>

    <table cellpadding="0" cellspacing="0" border="1" width="95%">
    <tr>
    <td>Column 1</td>
    </tr>
    <tr id="mcell" style="display: block;">
    <td>Column 2</td>
    </tr>
    </table>
    John Doe
    </body>
    </html>
    ---snip---


    Thanks in advance,

    -Tom
  • Nigel White

    #2
    Re: Show hide row in netscape using javascript

    Bagbourne" <the_bagbournes @btinternet.com > wrote in message
    news:bdona0$60u $1@sparta.btint ernet.com...[color=blue]
    > "Thomas Abraham" <thomas_rp@hotm ail.com> wrote in message
    > news:5cf0e3b0.0 306291817.3e39b f5b@posting.goo gle.com...[color=green]
    > > Hi,
    > >
    > > The following code to show and hide a row works fine in netscape 7 and
    > > IE 6. But everytime the cell is hidden and displayed in netscape, it
    > > adds a new line inside the cell. Please advise.[/color]
    >
    > Is it essential that you use a table? Could you use a series of DIVs?
    >[/color]

    This seems to work (tested on Opera, IE5, NS 6.2):

    <html>
    <head>
    <title>Table hide</title>
    <script language="javas cript">
    showRow = (navigator.appN ame.indexOf("In ternet Explorer") != -1) ? "block" :
    "table-row";
    function flipCell(count)
    {
    f = document.getEle mentById("mcell ");
    f.style.display = (f.style.displa y == "none") ? showRow : "none";
    }
    </script>
    </head>
    <body>
    <a href="javascrip t:flipCell(0)"> here</a>

    <table cellpadding="0" cellspacing="0" border="1" width="95%">
    <tr>
    <td>Column 1</td>
    </tr>
    <tr id="mcell">
    <td>Column 2</td>
    </tr>
    </table>
    John Doe
    </body>
    </html>

    Nige


    Comment

    • Richard Cornford

      #3
      Re: Show hide row in netscape using javascript

      "Nigel White" <NigelWhite@bag bourne.freeserv e.co.uk> wrote in message
      news:bdp1k8$r6$ 1@news7.svr.pol .co.uk...
      <snip>[color=blue]
      > This seems to work (tested on Opera, IE5, NS 6.2):
      >
      ><html>
      ><head>
      ><title>Table hide</title>
      ><script language="javas cript">
      >showRow = (navigator.appN ame.indexOf("In ternet Explorer") != -1) ?
      >"block" : "table-row";[/color]

      The problem with this is that there is no relationship between the
      navigator.appNa me property and the default CSS display property for a
      table row. Opera might take either option in this test based on user
      settings and other browsers that habitually spoof IE may have
      implemented the "table-row" CSS property.

      Fortunately the decision does not have to be made as it appears to be
      the case that browsers will take the setting of the display property to
      an empty string as equivalent to setting the property to the default
      value for that element, whatever that default value is.
      [color=blue]
      >function flipCell(count)
      >{
      > f = document.getEle mentById("mcell ");
      > f.style.display = (f.style.displa y == "none") ? showRow : "none";[/color]

      So:-

      f.style.display = (f.style.displa y == "none") ? "" : "none";
      [color=blue]
      > }
      > </script>
      > </head>
      > <body>
      > <a href="javascrip t:flipCell(0)"> here</a>[/color]
      <snip>

      The use of the javascript pseudo-protocol is ill advised as its use
      causes numerous unexpected and undesirable effects, some of which are
      browser, browser version and/or operating system dependent and thus
      difficult to identify:-

      <URL: http://jibbering.com/faq/#FAQ4_24 >

      Richard.

      --

      Example JavaScript DOM listings for: Opera 7.11,
      Mozilla 1.2 and ICEbrowser 5.4
      <URL: http://www.litotes.demon.co.uk/dom_root.html >


      Comment

      • Thomas Abraham

        #4
        Re: Show hide row in netscape using javascript

        Works perfectly! Thanks.


        "Nigel White" <NigelWhite@bag bourne.freeserv e.co.uk> wrote in message news:<bdp1k8$r6 $1@news7.svr.po l.co.uk>...[color=blue]
        > Bagbourne" <the_bagbournes @btinternet.com > wrote in message
        > news:bdona0$60u $1@sparta.btint ernet.com...[color=green]
        > > "Thomas Abraham" <thomas_rp@hotm ail.com> wrote in message
        > > news:5cf0e3b0.0 306291817.3e39b f5b@posting.goo gle.com...[color=darkred]
        > > > Hi,
        > > >
        > > > The following code to show and hide a row works fine in netscape 7 and
        > > > IE 6. But everytime the cell is hidden and displayed in netscape, it
        > > > adds a new line inside the cell. Please advise.[/color]
        > >
        > > Is it essential that you use a table? Could you use a series of DIVs?
        > >[/color]
        >
        > This seems to work (tested on Opera, IE5, NS 6.2):
        >
        > <html>
        > <head>
        > <title>Table hide</title>
        > <script language="javas cript">
        > showRow = (navigator.appN ame.indexOf("In ternet Explorer") != -1) ? "block" :
        > "table-row";
        > function flipCell(count)
        > {
        > f = document.getEle mentById("mcell ");
        > f.style.display = (f.style.displa y == "none") ? showRow : "none";
        > }
        > </script>
        > </head>
        > <body>
        > <a href="javascrip t:flipCell(0)"> here</a>
        >
        > <table cellpadding="0" cellspacing="0" border="1" width="95%">
        > <tr>
        > <td>Column 1</td>
        > </tr>
        > <tr id="mcell">
        > <td>Column 2</td>
        > </tr>
        > </table>
        > John Doe
        > </body>
        > </html>
        >
        > Nige[/color]

        Comment

        Working...