checkbox to hide/show table rows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mafonso
    New Member
    • Apr 2008
    • 2

    #16
    ...in my previous post I ment:

    .style.display = ...

    cheers.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #17
      Thanks for that info. Yes, that would set the default setting which could be block for IE and table-row for Firefox, not sure about others.

      Oh yeah, and welcome to the site :)

      Comment

      • saviola
        New Member
        • Jun 2010
        • 3

        #18
        Show and Hide DIV tag based on Checkbox selection

        Code:
        <head>
          <script language="javascript">
            function toggle(divId) {
            	var divArray = document.getElementsByTagName("div");
            	for(i = 0; i < divArray.length; i++){
            		if(divArray[i].className == divId){
            			if(divArray[i].style.display != 'none'){
            				divArray[i].style.display = 'none';
            			}else{
            				divArray[i].style.display = '';
            			}
            		}
            	}
            }
          </script>
        </head>
        <body>
          <form>
            <input type="checkbox" checked onClick="toggle('descr');"> See Descriptions
          </form>
          <div class="descr" style="display:none">Hello This is #1</div>
          <div class="descr" style="display:none">Hello This is #2</div>
          <div class="descr" style="display:none">Hello This is #3</div>
          <div class="non-descript">Hello This is not one of them</div>
        </body>
        Last edited by Dormilich; Jul 5 '10, 06:01 AM. Reason: Please use [code] tags when posting code

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #19
          PS. divArray is not an Array, it’s a so-called NodeList or HTMLCollection. you’ll notice the difference, when trying to use the Array methods.

          Comment

          Working...