Show/Hide layer in Netscape/IE problem

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

    Show/Hide layer in Netscape/IE problem

    Hi - I have a function which shows/hides a <div> on my page - this
    appears to oinly work in IE, but I also need it to work in Netscape 7.1.

    My function is in my head:

    function openIt(faq) {
    showIt = document.all(fa q);
    if (showIt.style.d isplay == "none") {
    showIt.style.di splay = ""
    } else {
    showIt.style.di splay = "none"
    }
    }

    ...and the onclick code is:

    <a href="#" onclick="Javasc ript:openIt('22 list'); return false;">click
    here to toggle</a>

    <div id="22list" style="display: none">
    This will show/hide when you click the above link
    </div>


    Could anyone help amend the function to run in both IE and Netscape?

    Thanks for any help,

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • David Dorward

    #2
    Re: Show/Hide layer in Netscape/IE problem

    Mark wrote:
    [color=blue]
    > Hi - I have a function which shows/hides a <div> on my page - this
    > appears to oinly work in IE, but I also need it to work in Netscape 7.1.[/color]

    I didn't even need to look at the rest of the code to see what was wrong.
    I'm sure a search in google groups would have found the answer, it seems to
    come up several times a week around here.

    <http://www.metalusions .com/backstage/articles/8/> appears to be a
    reasonable explanation.
    [color=blue]
    > <a href="#" onclick="Javasc ript:openIt('22 list'); return false;">click
    > here to toggle</a>[/color]

    (1) The "Javascript :" in the onclickj event is redundent.
    (2) href='#' is nasty. If you can't put a useful URL in there, don't use a
    link
    [color=blue]
    > <div id="22list" style="display: none">[/color]

    OK, I was wrong. I didn't guess what was wrong. Not everything at least. You
    have two problems. The solution to the first is above, the other is that
    ids may NOT begin with a number.

    <http://validator.w3.or g/>

    --
    David Dorward http://dorward.me.uk/

    Comment

    • Fabian

      #3
      Re: Show/Hide layer in Netscape/IE problem

      Mark hu kiteb:
      [color=blue]
      > Hi - I have a function which shows/hides a <div> on my page - this
      > appears to oinly work in IE, but I also need it to work in Netscape
      > 7.1.
      >
      > My function is in my head:
      >
      > function openIt(faq) {
      > showIt = document.all(fa q);
      > if (showIt.style.d isplay == "none") {
      > showIt.style.di splay = ""[/color]

      Change the above line to one of:

      showIt.style.di splay = "inline";
      showIt.style.di splay = "block";

      And then be aware of the difference between them, and use them
      appropriately.


      --
      --
      Fabian
      Visit my website often and for long periods!


      Comment

      • Richard Cornford

        #4
        Re: Show/Hide layer in Netscape/IE problem

        "Mark" <anonymous@devd ex.com> wrote in message
        news:3fc309cb$0 $193$75868355@n ews.frii.net...
        <snip>[color=blue]
        > function openIt(faq) {
        > showIt = document.all(fa q);[/color]

        Netscape/Mozilla/Gecko browsers do not have a document.all collection so
        the above line will produce errors and the rest of the function will not
        be executed.

        If the parameter - faq - contains a string that represents the unique ID
        of an HTML element (as appears to be the case, with the caveat that
        "22list" is not a valid ID attribute string according to the HTML 4
        specification) then the W3C DOM standard document.getEle mentById method
        could be used, possibly with a fall back to document.all to accommodate
        IE 4.

        Incidentally, document.all is an object so its named properties should
        be accessed using square brackets instead of parenthesise. IE does its
        error correcting/tolerance thing with code like this but other browsers
        that do implement a document.all collection (there are quite a number
        these days) may not be so tolerant.
        [color=blue]
        > if (showIt.style.d isplay == "none") {
        > showIt.style.di splay = ""
        > } else {
        > showIt.style.di splay = "none"
        > }
        > }
        >
        > ..and the onclick code is:
        >
        > <a href="#" onclick="Javasc ript:openIt('22 list');
        >return false;">click here to toggle</a>
        >
        > <div id="22list" style="display: none">[/color]
        <snip>

        Initially setting the display property to none means that any visitors
        to the page who have JavaScript disabled/unavailable will be presented
        with a non-functional/useful link and never be able to view the content
        of the DIV (unless they view the page source). Generally, if content is
        to be hidden and revealed with scripts it would be better to have it
        initially visible and hide it in the onload event so that the content
        will be available to the users without JavaScript. Additionally, the
        link is meaningless without scripting so it should probably be included
        in the document using a script, so that without client-side scripting
        the user doesn't ever get the impression that there was any dynamic
        mechanism on the page, and certainly not the impression that it is
        broken.

        Richard.


        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: Show/Hide layer in Netscape/IE problem

          "Fabian" <lajzar@hotmail .com> writes:
          [color=blue]
          > Mark hu kiteb:[/color]
          [color=blue][color=green]
          >> showIt.style.di splay = ""[/color]
          >
          > Change the above line to one of:
          >
          > showIt.style.di splay = "inline";
          > showIt.style.di splay = "block";[/color]

          That's not necessary. Setting the properties of the element's style
          object corresponds to writing in the tag's style attribute. Setting
          a style object property to the empty string is consistently (across
          current browsers) equivalent to removing the property from the
          attribute value. It will then take its default value (or whatever
          value is given by global CSS rules).

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • Mark

            #6
            Re: Show/Hide layer in Netscape/IE problem

            Hi - thank you for the replies - I'm not good with JavaScript though -
            all I've been able to manage (after quite some time) is the code I've
            shown - this was all through trial and error. Does anyone have a proper
            routine which will both check for IE and Netscape, and toggle the
            visibility/hidden/block (not sure which now!) between being shown and
            not being shown - and not to leave a big gap if it is not shown?

            Thanks again,



            *** Sent via Developersdex http://www.developersdex.com ***
            Don't just participate in USENET...get rewarded for it!

            Comment

            Working...