JavaScript/CSS/DOM issue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • earl.robb@gmail.com

    JavaScript/CSS/DOM issue

    Please excuse me If I am posting to the wrong group. I was recommended
    here from one of the Database groups I regularly track.

    I have a small script that loads a table with some elements visiblity =
    hidden and display = none. When clicking on the link it "opens" the
    hidden table elements. When click on the link again it "hides" the
    elements.

    Now this works dandy in IE but in FireFox the element "opens" but when
    you click on it again to "hide" the text in the cell disappears but the
    actual element itself does not "dissappear " leaving a big blank space.

    Working sample is here http://www.jhdesigninc.com/testJava.asp Its not
    "pretty" because I eliminated all the code I possible could to make the
    problem easier to understand.

    Code Sample-----------------
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <Meta Http-Equiv="Content-Type" Content="text/html;
    charset=iso-8859-1">
    <titleblah-blah </title>
    <style type="text/css">
    <!--
    ..style1 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    }
    -->
    </style>


    <script type="text/JavaScript">
    function changeView(objC hange){
    /*have tried sniffing browser and not using getElement
    didnt seem to help with display or visibilty
    Im missing something really basic
    */
    if (document.getEl ementById(objCh ange).style.vis ibility ==
    'visible'){
    document.getEle mentById(objCha nge).style.disp lay = "none";
    document.getEle mentById(objCha nge).style.visi bility = "hidden";
    } else {
    document.getEle mentById(objCha nge).style.disp lay = "block";
    document.getEle mentById(objCha nge).style.visi bility =
    "visible";
    }

    }
    </SCRIPT>
    </head>
    <body>

    <table width="449" border="0" cellspacing="1" cellpadding="1" >
    <tr valign="top">
    <td width="100%" align="left" nowrap<span class="style1"> Click on
    the LINK Its works in IE and Netscape but not Fox. <br>

    The window does not go to display:none and visibility:hidd en<br>
    In Firefox compare IE and Firefox by clicking on the view<br>
    button multiple times in both browsers
    </span><br>
    <br>
    <BR>

    <table width="100%" border="0" cellspacing="2" cellpadding="0"
    id="clickTbl">
    <tr class="tblHeade r">
    <td class="tblHeade r">Approver</td>
    <td class="tblHeade r">Status</td>

    <td class="tblHeade r">Date</td>
    <td class="tblHeade r">Time</td>
    <td class="tblHeade r">Notes</td>
    </tr>
    <tr>
    <td>Bill Gordon</td>
    <td>&nbsp;Await ing Approval</td>

    <td>&nbsp;Pendi ng</td>
    <td>&nbsp;Pendi ng</td>
    <td>&nbsp;<a href="#" onClick="change View('notes');" >View
    </a></td>
    </tr>
    <tr id="notes" style="visibili ty:hidden; display:none;">
    <td colspan="5" bgcolor="#99339 9"><p>some tesa safd asfd
    asddfdasdf
    fasd fasfd as dfas df asdf asdf asdf as dfas df asdf asd
    f asdf
    asdf asd asdfasda</p>
    <p>asdasdfasd f</p>

    <p>asdf</p>
    <p>a</p>
    <p>sdf </p></td>
    </tr>
    <tr>
    <td>Brenda Hudson</td>
    <td>&nbsp;Und er Review</td>

    <td>&nbsp;Pendi ng</td>
    <td>&nbsp;Pendi ng</td>
    <td>&nbsp;Cel l Below Not Relevant</td>
    </tr>
    </table></td>
    </tr>
    </table>
    </body>

    </html>
    End Code-------------------------------

    Any help would be greatly appreciated.

    Thanks,
    Earl

  • Martin Honnen

    #2
    Re: JavaScript/CSS/DOM issue



    earl.robb@gmail .com wrote:

    I have a small script that loads a table with some elements visiblity =
    hidden and display = none. When clicking on the link it "opens" the
    hidden table elements. When click on the link again it "hides" the
    elements.
    >
    Now this works dandy in IE but in FireFox the element "opens" but when
    you click on it again to "hide" the text in the cell disappears but the
    actual element itself does not "dissappear " leaving a big blank space.
    First of all if you toggle the CSS display property to show/hide
    elements then there is no need at all to toggle the CSS visibility
    property as well. You can leave visibility alone and simply toggle display.
    Then the remaining problem is that CSS 2 defines various possible
    display values, for table row elements like the HTML tr elements
    'table-row' is the right value and not 'block'. Only IE till version 6
    does not support that.
    As long as you are using inline styles the solution however is simple:
    to hide set e.g.
    elementObject.s tyle.display = 'none';
    to show it suffices to do
    elementObject.s tyle.display = '';


    --

    Martin Honnen

    Comment

    • petermichaux@gmail.com

      #3
      Re: JavaScript/CSS/DOM issue

      earl.robb@gmail .com wrote:
      I have a small script that loads a table with some elements visiblity =
      hidden and display = none. When clicking on the link it "opens" the
      hidden table elements. When click on the link again it "hides" the
      elements.
      Hi Earl,

      I played with your example and think i found the problem. You are using
      display="block" for a table row when it should be display="table-row".

      You don't need to toggle both "display" and "visibility . Just toggling
      "display" should be fine. If you want to toggle "visibility " you can do
      that too but it shouldn't make a difference.

      Nested tables are scary and probably not necessary.

      The "return false;" I added makes it so the URL doesn't have a '#'
      after clicking the link

      Adjusted example below.

      -Peter


      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd">
      <html>
      <head>
      <Meta Http-Equiv="Content-Type" Content="text/html;
      charset=iso-8859-1">
      <titleblah-blah </title>

      <script type="text/javascript">

      function changeView(objC hange){
      var el = document.getEle mentById(objCha nge)
      if (el){
      if (el.style.displ ay.toLowerCase( ) !== 'none'){
      el.style.displa y = "none";
      } else {
      el.style.displa y = "table-row";
      // this works too as long as the display style is not set in
      a css file etc
      //el.style.displa y = "";
      }
      }
      }


      </script>
      </head>
      <body>

      <p>
      Click on the LINK Its works in IE and Netscape but not Fox.
      The window does not go to display:none and visibility:hidd en
      In Firefox compare IE and Firefox by clicking on the view
      button multiple times in both browsers
      </p>

      <table width="100%" border="0" cellspacing="2" cellpadding="0"
      id="clickTbl">
      <tr>
      <td>Bill Gordon</td>
      <td>Awaiting Approval</td>
      <td>Pending</td>
      <td>Pending</td>
      <td><a href="#" onClick="change View('notes');r eturn
      false;">View</a></td>
      </tr>
      <tr id="notes" style="display: none">
      <td colspan="5" bgcolor="#99339 9">
      <p>some tesa safd asfd asddfdasdf
      fasd fasfd as dfas df asdf asdf asdf as dfas df asdf asdf asdf
      asdf asd asdfasda</p>
      <p>asdasdfasd f</p>
      <p>asdf</p>
      <p>a</p>
      <p>sdf </p>
      </td>
      </tr>
      <tr>
      <td>Brenda Hudson</td>
      <td>Under Review</td>
      <td>Pending</td>
      <td>Pending</td>
      <td>Cell Below Not Relevant</td>
      </tr>
      </table>

      </body>
      </html>

      Comment

      • surf_doggie

        #4
        Re: JavaScript/CSS/DOM issue

        Thank you peter & martin for your input. If I am missing something you
        are telling me bang me over the head with it.

        I have tried elementObject.s tyle.display = 'none'; and it did not
        rectify the issue
        elementObject.s tyle.display = ''; as far as I know that call is
        invalid.

        If you have it working with Firefox can you just send me a link so I
        can see what needs to be done.

        Im sorry Table-row has nothing to do with the issue. The issue is the
        html element will not collapse again. I know how to adjust the display
        I dont know how to Collapse the element again.

        Earl

        Comment

        • petermichaux@gmail.com

          #5
          Re: JavaScript/CSS/DOM issue


          surf_doggie wrote:
          Thank you peter & martin for your input. If I am missing something you
          are telling me bang me over the head with it.
          >
          I have tried elementObject.s tyle.display = 'none'; and it did not
          rectify the issue
          elementObject.s tyle.display = ''; as far as I know that call is
          invalid.
          >
          If you have it working with Firefox can you just send me a link so I
          can see what needs to be done.
          >
          Im sorry Table-row has nothing to do with the issue. The issue is the
          html element will not collapse again. I know how to adjust the display
          I dont know how to Collapse the element again.
          >
          Earl
          Did you try the example I posted in Firefox? It works for me.

          Peter

          Comment

          • ASM

            #6
            Re: JavaScript/CSS/DOM issue

            earl.robb@gmail .com a écrit :
            I have a small script that loads a table with some elements visiblity =
            hidden and display = none. When clicking on the link it "opens" the
            hidden table elements. When click on the link again it "hides" the
            elements.
            >
            Now this works dandy in IE but in FireFox the element "opens" but when
            you click on it again to "hide" the text in the cell disappears but the
            actual element itself does not "dissappear " leaving a big blank space.
            >
            Working sample is here http://www.jhdesigninc.com/testJava.asp
            It is tipicaly a misundertanding about css rules in IE.
            IE needs 'block' and FireFox (and others) wants 'table-row' for rule
            'display' about rows in table.

            As you want to hide a TR, the best way is to undisplay it
            Then to show it again you just need to give it back it's natural appearance.

            Of course, your TR 'notes' has no rule to hide him in "normal" view.
            It's *JS who has to* do the job ( onload = function ...)

            Code Sample-----------------
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/html4/loose.dtd">
            <html>
            [snip]

            <script type="text/JavaScript">
            function changeView(objC hange){
            var objToChge = document.getEle mentById(objCha nge).style;
            objToChge.displ ay = objToChge.displ ay==''? 'none' : '';
            }
            onload = function() { changeView('not es'); };
            </script>

            [re-snip]
            </tr>
            <tr id="notes">
            <td colspan="5" bgcolor="#99339 9"><p>some tesa safd asfd
            [etc...]
            </html>

            --
            Stephane Moriaux et son [moins] vieux Mac

            Comment

            • surf_doggie

              #7
              Re: JavaScript/CSS/DOM issue

              Yes Peter I have tried table-row. I will try it again and see if it
              closes the table.

              document.getEle mentById(objCha nge).style.disp lay = "table-row"; does
              not work in Fox which is where I am looking for the solution. In
              addition it breaks IE.

              I know table-row for the display I can sniff.

              My quandry is how do I get the element to disappear in Fox. If you
              click on it multiple times it keeps adding space and wholes. It never
              collapes's

              Any ideas?

              Earl

              Comment

              • surf_doggie

                #8
                Re: JavaScript/CSS/DOM issue

                Where is the link that works?

                Comment

                • petermichaux@gmail.com

                  #9
                  Re: JavaScript/CSS/DOM issue


                  surf_doggie wrote:
                  Where is the link that works?
                  It wasn't a link. Here it is again. But if what ASM posted is true then
                  you should use the el.style.displa y = "" option instead of
                  el.style.displa y = "table-row" in the following example so it works in
                  firefox and ie.

                  Peter



                  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                  "http://www.w3.org/TR/html4/loose.dtd">
                  <html>
                  <head>
                  <Meta Http-Equiv="Content-Type" Content="text/html;
                  charset=iso-8859-1">
                  <titleblah-blah </title>

                  <script type="text/javascript">

                  function changeView(objC hange){
                  var el = document.getEle mentById(objCha nge)
                  if (el){
                  if (el.style.displ ay.toLowerCase( ) !== 'none'){
                  el.style.displa y = "none";
                  } else {
                  el.style.displa y = "table-row";
                  // this works too as long as the display style is not set in
                  a css file etc
                  //el.style.displa y = "";
                  }
                  }
                  }

                  </script>
                  </head>
                  <body>

                  <p>
                  Click on the LINK Its works in IE and Netscape but not Fox.
                  The window does not go to display:none and visibility:hidd en
                  In Firefox compare IE and Firefox by clicking on the view
                  button multiple times in both browsers
                  </p>

                  <table width="100%" border="0" cellspacing="2" cellpadding="0"
                  id="clickTbl">
                  <tr>
                  <td>Bill Gordon</td>
                  <td>Awaiting Approval</td>
                  <td>Pending</td>
                  <td>Pending</td>
                  <td><a href="#" onClick="change View('notes');r eturn
                  false;">View</a></td>
                  </tr>
                  <tr id="notes" style="display: none">
                  <td colspan="5" bgcolor="#99339 9">
                  <p>some tesa safd asfd asddfdasdf
                  fasd fasfd as dfas df asdf asdf asdf as dfas df asdf asdf asdf
                  asdf asd asdfasda</p>
                  <p>asdasdfasd f</p>
                  <p>asdf</p>
                  <p>a</p>
                  <p>sdf </p>
                  </td>
                  </tr>
                  <tr>
                  <td>Brenda Hudson</td>
                  <td>Under Review</td>
                  <td>Pending</td>
                  <td>Pending</td>
                  <td>Cell Below Not Relevant</td>
                  </tr>
                  </table>

                  </body>
                  </html>

                  Comment

                  • ASM

                    #10
                    Re: JavaScript/CSS/DOM issue

                    surf_doggie a écrit :
                    Yes Peter I have tried table-row. I will try it again and see if it
                    closes the table.
                    >
                    document.getEle mentById(objCha nge).style.disp lay = "table-row"; does
                    not work in Fox which is where I am looking for the solution. In
                    addition it breaks IE.
                    Any ideas?
                    You absolutely not have to use neither 'table-row' nor 'block'.
                    You have to use the inverse method

                    1) hide : display = 'none';
                    2) show : display = '';

                    Any of your elements to hide are styled in {display:none}
                    JavaScript will hide what you want on loading page
                    Then your link or button will alternatively show / hide what was hidden

                    There is no other "clean" way to do.

                    <html>
                    <script type="text/javascript">
                    function switcher(boxId) {
                    var box = document.getEle mentById(boxId) .style;
                    box.display = box.display=='' ? 'none' : '';
                    }
                    onload = function() { switcher('row') ;}
                    </script>
                    <a href="#" onclick="switch er('row');retur n false">swith row</a>
                    <table border=2 cellspacing=5>
                    <tr id="row" bgcolor="#ffffc c">
                    <td height=120>to see</td><td>what appends</td>
                    </tr><tr>
                    <td>something </td><td>here</td>
                    </tr>
                    </table>
                    </html>

                    --
                    Stephane Moriaux et son [moins] vieux Mac

                    Comment

                    • surf_doggie

                      #11
                      Re: JavaScript/CSS/DOM issue

                      ASM:
                      I have to ask because I am trying to solve the issue of the block not
                      closing. I have heard alot about table-row. Sorry Im dense but that
                      will collapse the table row?

                      I appreciate all the help Im but I cant get the table row to collapse.

                      It would seem to me that it wouldnt matter if I called table-row or
                      block when I call .style.display = "none"; and .style.visibili ty =
                      "hidden";

                      In FoxFire that it would collapse the same way it does in IE.
                      All I am looking for is to be able to collapse the table in Fox the
                      same way it does in IE. Im sorry Im not getting it and you guys have it
                      figured out can someone tell me where I am failing?

                      Earl

                      Comment

                      • surf_doggie

                        #12
                        Re: JavaScript/CSS/DOM issue

                        You all have been great testing peters solution will let you know in
                        the am.

                        Thanks all

                        Comment

                        • ASM

                          #13
                          Re: JavaScript/CSS/DOM issue

                          surf_doggie a écrit :
                          ASM:
                          Dear Earl Doggle Surf,

                          It would be better you keep in your posts some text from post you're
                          answering.

                          It is very difficult to follow what about you're speaking.

                          Can't you use preferences of your Mozilla Messenger ?
                          (somewhere it's question of news and/or forums)
                          I have to ask because I am trying to solve the issue of the block not
                          closing. I have heard alot about table-row. Sorry Im dense but that
                          will collapse the table row?
                          To hide a block or any element : visibility: hidden;
                          To disappear a block or an elemt : display: none;

                          Both actions are not same,
                          - 1st : un-show the element but keep place for it
                          - 2nd : un-display the element -no place kept

                          You have to decide *which one* of these two methods you want, and then
                          to adopt the right method for its contrario.

                          Revealing a hidden is quit easy : visibility: visible;

                          But to reveal a non displayed element is more difficult,
                          you need to know at what kind of element you tell :
                          is it of type : image, block, in-line, table, table-row etc... ?

                          IE, with it's approximations and it's unknowing correct css, cause
                          problem so we avoid to have to precise this element properties.

                          display off : myElement.style .display = 'none';
                          display back : myElement.style .display = '';

                          absolutely used in this order.

                          And switchering is obtained with :

                          myElement.style .display = myElement.style .display == ''?
                          'none' : '' ;

                          or in long code :

                          if(myElement.st yle.display == '') myElement.style .display = 'none';
                          else
                          myElement.style .display = '';

                          This method is available for all styles, of course.
                          I appreciate all the help Im but I cant get the table row to collapse.
                          Did you try the example code given in my percedent posts ?
                          (copy that code and paste it in your notePad and save it in html
                          extension, then try it in your browsers)
                          The last one is a very basic example I think not too much difficult to
                          understand.
                          It would seem to me that it wouldnt matter if I called table-row or
                          block when I call .style.display = "none"; and .style.visibili ty =
                          "hidden";
                          See above (it's one or other : display OR visible)

                          If you set style to 'none' it is none, nothing, nada, rien ...
                          (whatever the element is)

                          To style back your element
                          you just need to tell there is no more style added -'';
                          Translation : style is empty (different of nada, nothing)

                          In FoxFire that it would collapse the same way it does in IE.
                          use correct method given.
                          All I am looking for is to be able to collapse the table in Fox the
                          same way it does in IE. Im sorry Im not getting it and you guys have it
                          figured out can someone tell me where I am failing?
                          You're failling in :
                          - css using (and their significations)
                          - no easy possibility to correctly address to a table row

                          The way is to use the default mechanisms of browsers :
                          they know what are the proprieties of element called
                          even if they do not name them same way.


                          --
                          Stephane Moriaux et son [moins] vieux Mac

                          Comment

                          • surf_doggie

                            #14
                            Re: JavaScript/CSS/DOM issue

                            Thanks ASM I appreciate all the help the room has givin me lots of good
                            people here. As I suspected the issue was really silly.
                            is it of type : image, block, in-line, table, table-row etc... ?
                            Yes I now have to sniff the browser and use table-row for a correct
                            display but the issue of the table-row collapsing in FireFox was really
                            a silly mistake. To correct the issue in Firefox I changed

                            <tr id="notes" style="visibili ty:hidden; display:none;">
                            <td colspan="5" bgcolor="#99339 9"--------
                            TO

                            <tr>
                            <td colspan="5" bgcolor="#99339 9" id="notes" style="visibili ty:hidden;
                            display:none;">-----

                            Time to start cleaning up code and making it tighter thank you all for
                            your help with this.

                            In the future I will remember to quote ASM good point about
                            understanding whats going especially if your getting email
                            notifications

                            Earl




                            ASM wrote:
                            surf_doggie a écrit :
                            ASM:
                            >
                            Dear Earl Doggle Surf,
                            >
                            It would be better you keep in your posts some text from post you're
                            answering.
                            >
                            It is very difficult to follow what about you're speaking.
                            >
                            Can't you use preferences of your Mozilla Messenger ?
                            (somewhere it's question of news and/or forums)
                            >
                            I have to ask because I am trying to solve the issue of the block not
                            closing. I have heard alot about table-row. Sorry Im dense but that
                            will collapse the table row?
                            >
                            To hide a block or any element : visibility: hidden;
                            To disappear a block or an elemt : display: none;
                            >
                            Both actions are not same,
                            - 1st : un-show the element but keep place for it
                            - 2nd : un-display the element -no place kept
                            >
                            You have to decide *which one* of these two methods you want, and then
                            to adopt the right method for its contrario.
                            >
                            Revealing a hidden is quit easy : visibility: visible;
                            >
                            But to reveal a non displayed element is more difficult,
                            you need to know at what kind of element you tell :
                            is it of type : image, block, in-line, table, table-row etc... ?
                            >
                            IE, with it's approximations and it's unknowing correct css, cause
                            problem so we avoid to have to precise this element properties.
                            >
                            display off : myElement.style .display = 'none';
                            display back : myElement.style .display = '';
                            >
                            absolutely used in this order.
                            >
                            And switchering is obtained with :
                            >
                            myElement.style .display = myElement.style .display == ''?
                            'none' : '' ;
                            >
                            or in long code :
                            >
                            if(myElement.st yle.display == '') myElement.style .display = 'none';
                            else
                            myElement.style .display = '';
                            >
                            This method is available for all styles, of course.
                            >
                            I appreciate all the help Im but I cant get the table row to collapse.
                            >
                            Did you try the example code given in my percedent posts ?
                            (copy that code and paste it in your notePad and save it in html
                            extension, then try it in your browsers)
                            The last one is a very basic example I think not too much difficult to
                            understand.
                            >
                            It would seem to me that it wouldnt matter if I called table-row or
                            block when I call .style.display = "none"; and .style.visibili ty =
                            "hidden";
                            >
                            See above (it's one or other : display OR visible)
                            >
                            If you set style to 'none' it is none, nothing, nada, rien ...
                            (whatever the element is)
                            >
                            To style back your element
                            you just need to tell there is no more style added -'';
                            Translation : style is empty (different of nada, nothing)
                            >
                            >
                            In FoxFire that it would collapse the same way it does in IE.
                            >
                            use correct method given.
                            >
                            All I am looking for is to be able to collapse the table in Fox the
                            same way it does in IE. Im sorry Im not getting it and you guys have it
                            figured out can someone tell me where I am failing?
                            >
                            You're failling in :
                            - css using (and their significations)
                            - no easy possibility to correctly address to a table row
                            >
                            The way is to use the default mechanisms of browsers :
                            they know what are the proprieties of element called
                            even if they do not name them same way.


                            --
                            Stephane Moriaux et son [moins] vieux Mac

                            Comment

                            • ASM

                              #15
                              Re: JavaScript/CSS/DOM issue

                              surf_doggie a écrit :
                              Thanks ASM I appreciate all the help the room has givin me lots of good
                              people here. As I suspected the issue was really silly.
                              >
                              >is it of type : image, block, in-line, table, table-row etc... ?
                              Some progress in posting :-)
                              Yes I now have to sniff the browser
                              absolutely not

                              You turn the problen in wrong way and never you'l really get absolute
                              satisfaction.
                              I changed TO
                              >
                              <tr>
                              <td colspan="5" bgcolor="#99339 9" id="notes" style="visibili ty:hidden;
                              display:none;">
                              And it is a very bad way to do !
                              How visitor with JS disabled will can see this element ?

                              Don't tell me he turns on his JS.
                              As he see nothing it can't know there would be something to see.

                              Last time I tell it : the element must be hide by javascript.

                              With bonus : show is very easy.

                              --
                              Stephane Moriaux et son [moins] vieux Mac

                              Comment

                              Working...