Showing and Hiding

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

    #1

    Showing and Hiding

    I have this function that shows or hides text on the page... and it
    works great in IE... but I can't make it work in Mozilla type
    browsers.. I tried reading up about different things to do... but
    nothing I tried works... Can someone please help me?

    <head>
    <script language="JavaS cript">

    function toggleDisplay(o bjRef){
    objRef.style.di splay = (objRef.style.d isplay=="none") ? "" : "none";
    }

    </script>
    </head>
    <body>

    <a href=javascript :toggleDisplay( text1)>Test</a>

    <div id="text1" style="display: none;">
    here is some text....
    </div>

    </body>


    Thanks for any help you can give me!!!

    -Sarah
  • Ivo

    #2
    Re: Showing and Hiding

    "Sarah" <no-spam~sarah@zhou se.com> wrote in message
    news:9vgt305aam kgne1hlhjoi7g8v 0esaq1se4@4ax.c om...[color=blue]
    > I have this function that shows or hides text on the page... and it
    > works great in IE... but I can't make it work in Mozilla type
    > browsers.. I tried reading up about different things to do... but
    > nothing I tried works... Can someone please help me?
    >
    > <head>
    > <script language="JavaS cript">[/color]

    The language attribute should no longer be used. It is now recommended to
    write <script type="text/javascript"> instead. Don't ask me why. And don't
    ask the sites where you 've been reading either. They are at least two years
    behind their schedule.
    [color=blue]
    > function toggleDisplay(o bjRef){
    > objRef.style.di splay = (objRef.style.d isplay=="none") ? "" : "none";
    > }
    >
    > </script>
    > </head>
    > <body>
    > <a href=javascript :toggleDisplay( text1)>Test</a>[/color]

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

    HTH
    Ivo


    Comment

    • Sarah

      #3
      Re: Showing and Hiding

      >[color=blue]
      >Perhaps see <URL: http://jibbering.com/faq/#FAQ4_24>
      >
      >HTH
      >Ivo
      >[/color]
      Thanks.... That's very helpful... Do you happen to have a FAQ that
      actually answers my question? :)

      Comment

      • Michael Winter

        #4
        Re: Showing and Hiding

        On Fri, 27 Feb 2004 07:08:11 +0100, Ivo <no@thank.you > wrote:
        [color=blue]
        > "Sarah" <no-spam~sarah@zhou se.com> wrote in message
        > news:9vgt305aam kgne1hlhjoi7g8v 0esaq1se4@4ax.c om...
        >[color=green]
        >> I have this function that shows or hides text on the page... and it
        >> works great in IE... but I can't make it work in Mozilla type
        >> browsers.. I tried reading up about different things to do... but
        >> nothing I tried works... Can someone please help me?
        >>
        >> <head>
        >> <script language="JavaS cript">[/color]
        >
        > The language attribute should no longer be used. It is now recommended to
        > write <script type="text/javascript"> instead. Don't ask me why. And
        > don't ask the sites where you 've been reading either. They are at least
        > two years behind their schedule.[/color]

        Two? Try six. That's how long language has been deprecated. :)

        As for an explanation, read my post in reply to Erwin Moller's, "Use of
        type and/or language in script-tag", posted 19 February. No-one trashed my
        reasoning, so you might assume it's at least somewhat correct.
        [color=blue][color=green]
        >> function toggleDisplay(o bjRef){
        >> objRef.style.di splay = (objRef.style.d isplay=="none") ? "" : "none";
        >> }
        >>
        >> </script>
        >> </head>
        >> <body>
        >> <a href=javascript :toggleDisplay( text1)>Test</a>[/color]
        >
        > Perhaps see <URL: http://jibbering.com/faq/#FAQ4_24>[/color]

        Though that's a good place to start, the problem is with the use of
        'text1'. Putting that fact that it's a bad identifier aside, the OP is
        using it as a global variable. It is not - it's the id of a DIV.

        The OP might want to try using:

        function getRefById( id ) {
        if( document.getEle mentById ) {
        return document.getEle mentById( id );
        } else if( document.all ) {
        return document.all[ id ];
        }
        return null;
        }
        ...
        toggleDisplay( getRefById( 'text1' ))

        Mike

        --
        Michael Winter
        M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

        Comment

        • Robert Meineke

          #5
          Re: Showing and Hiding

          > I have this function that shows or hides text on the page... and it[color=blue]
          > works great in IE... but I can't make it work in Mozilla type
          > browsers.. I tried reading up about different things to do... but
          > nothing I tried works... Can someone please help me?
          >
          > <head>
          > <script language="JavaS cript">
          >
          > function toggleDisplay(o bjRef){
          > objRef.style.di splay = (objRef.style.d isplay=="none") ? "" : "none";
          > }
          >
          > </script>
          > </head>
          > <body>
          >
          > <a href=javascript :toggleDisplay( text1)>Test</a>
          >
          > <div id="text1" style="display: none;">
          > here is some text....
          > </div>
          >
          > </body>[/color]

          Watch the line-wrapping but this works in NN7 and IE5.5 ...
          <html>
          <head>
          <script language="JavaS cript">
          function toggleDisplay(o bjId){
          document.getEle mentById(objId) .style.display =
          (document.getEl ementById(objId ).style.display =="none") ? "" : "none";
          }
          </script>
          </head>
          <body>
          <a href=javascript :toggleDisplay( 'text1')>Test</a>
          <div id="text1" style="display: none;">
          here is some text....
          </div>
          </body>
          </html>

          Comment

          • Sarah

            #6
            Re: Showing and Hiding

            Thank you very much for helping me Robert... that works great...

            Best wishes,

            -Sarah

            Comment

            Working...