DHTML in Netscape

Discussion in 'HTML' started by WJ, Nov 1, 2004.

  1. WJ

    WJ Guest

    I have some DHTML that is showing and hiding a div. This works in IE and
    Firefox, but not in Netscape.

    <html>
    <head>
    <script language="javascript">
    function switchDisplay()
    {
    if (myDiv.style.display=='block')
    myDiv.style.display='none';
    else
    myDiv.style.display='block';
    }
    </script>
    </head>
    <body>
    <form myform. . . >
    <myDiv style="display:block">
    blah
    </myDiv>
    <input type="button" value="test me" onclick="javascript:
    switchDisplay();">
    </form>


    </body>
    </html>

    In the javascript, I can refer to the div directly in IE and Firefox (and
    Mozilla). It does nothing in Netscape.

    I've tried document.myDiv.style.display,
    document.elements['myDiv'].style.display, and trying to walk the DOM through
    the form.

    Any suggestions would be greatly appreciated.

    Thx!
     
    WJ, Nov 1, 2004
    #1
    1. Advertising

  2. WJ wrote:

    > I have some DHTML that is showing and hiding a div. This works in IE and
    > Firefox, but not in Netscape.


    Netscape what? 3 or less? 4.x? or 6 and above?

    3 doesn't do "DHTML".
    4 is a buggy nightmare with dwindling market hare and not worth worrying
    about.
    6 should support pretty much anything any other Gecko based browser
    supports.

    > <html>
    > <head>
    > <script language="javascript">


    The Language attribute is deprecated, and the type attribute is required.

    > function switchDisplay()
    > {
    > if (myDiv.style.display=='block')


    What is "myDiv"? You need to use document.getElementById (or document.all
    for ancient versions of IE, or goodness knows what for Netscape 4) to get
    an object reference first.

    > <myDiv style="display:block">


    There is no "myDiv" element in HTML.

    > <input type="button" value="test me" onclick="javascript:
    > switchDisplay();">


    Loose the "javascript:" bit.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Nov 1, 2004
    #2
    1. Advertising

  3. WJ

    Toby Inkster Guest

    WJ wrote:

    > I have some DHTML that is showing and hiding a div. This works in IE and
    > Firefox, but not in Netscape.


    What do you mean by "Netscape"? There are significant differences between,
    say, Netscape 4.08 and Netscape 7.1.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Nov 1, 2004
    #3
  4. WJ

    WJ Guest

    Most humble apologies. I'm trying this with Netscape 7.2 The Div is
    <div name="myDiv" id="myDiv" style="display:block">

    .. . .

    </div>
     
    WJ, Nov 1, 2004
    #4
  5. WJ

    Toby Inkster Guest

    WJ wrote:

    > function switchDisplay()
    > {
    > if (myDiv.style.display=='block')
    > myDiv.style.display='none';
    > else
    > myDiv.style.display='block';
    > }


    Function should read:

    function switchDisplay() {
    myDiv = document.getElementById('myDiv');
    if (myDiv.style.display=='block') myDiv.style.display='none';
    else myDiv.style.display='block';
    }

    > <div name="myDiv" id="myDiv" style="display:block">
    > . . .
    > </div>


    HTML should read:

    <div id="myDiv">...</div>

    The other attributes style/name are not needed.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Nov 1, 2004
    #5
  6. WJ

    DU Guest

    WJ wrote:
    > Most humble apologies. I'm trying this with Netscape 7.2 The Div is
    > <div name="myDiv" id="myDiv" style="display:block">
    >
    > . . .
    >
    > </div>
    >
    >
    >


    There is no name attribute for div elements. Also, I recommend to never
    use the same identifier for name and id attributes.
    As mentioned by others, style="display:block" is also pointless as this
    is the default display declaration in all CSS-capable browsers.

    DU
    --
    The site said to use Internet Explorer 5 or better... so I switched to
    Mozilla 1.7.3 :)
     
    DU, Nov 4, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom
    Replies:
    0
    Views:
    513
  2. Mickey Segal
    Replies:
    1
    Views:
    691
    Mickey Segal
    May 21, 2004
  3. yaktipper
    Replies:
    10
    Views:
    304
    Richard Cornford
    Jul 10, 2003
  4. Catherine Lynn Smith

    Netscape DHTML not working

    Catherine Lynn Smith, Oct 14, 2003, in forum: Javascript
    Replies:
    1
    Views:
    148
    Martin Honnen
    Oct 14, 2003
  5. Steve
    Replies:
    1
    Views:
    310
    Richard Cornford
    Apr 9, 2005
Loading...

Share This Page