SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Nov 2006
    Location
    Berlin
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question question on grouped checkbox selection

    Hello,

    how it is possible to check if an entry in the following code is duplicate and remove this afterwards?

    HTML Code:
    <html>
    <head></head>
    <body>
    <script language="JavaScript">
      function getElementsByClass(searchClass,node,tag) {
        var classElements = new Array();
        if ( node == null )
          node = document;
        if ( tag == null )
          tag = '*';
        var els = node.getElementsByTagName(tag);
        var elsLen = els.length;
        var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
        for (i = 0, j = 0; i < elsLen; i++) {
          if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
          }
        }
        return classElements;
      }
    
      function clicked( checked, name ) {
        e = getElementsByClass( name, document.getElementById( 'grouptable' ), 'tr' ) ;
        if( e ) {
          if( e.length ) {
            for( i = 0 ; i < e.length ; i++ ) {
              e[ i ].style.display = checked ? '' : 'none' ;
            }
          }
        }
      }
    
    </script>
    <form name="myForm" id="myFormID" method="post">
    
    <input type="checkbox" name="cat_1" value="1" onclick="clicked( this.checked, 'channel1' )">Category 1</input><br>
    <input type="checkbox" name="cat_2" value="1" onclick="clicked( this.checked, 'channel2' )">Category 2</input><br>
    <input type="checkbox" name="cat_3" value="1" onclick="clicked( this.checked, 'channel3' )">Category 3</input><br>
    <br><br>
    <table id="grouptable">
     <tr class="channel1" style="display:none">
       <!-- duplicate entry - has to be removed based on first selection of checkbox-->
       <td>InfoChannel - duplicate entry</td>
     </tr>
     <tr class="channel1" style="display:none">
       <td>NewsChannel</td>
     </tr>
     <tr class="channel1" style="display:none">
       <td>DocuChannel</td>
     </tr>
     <tr class="channel2" style="display:none">
       <!-- duplicate entry - has to be removed based on first selection of checkbox-->
       <td>InfoChannel</td>
     </tr>
     <tr class="channel2" style="display:none">
       <td>NatureChannel</td>
     </tr>
     <tr class="channel3" style="display:none">
       <td>MovieChannel</td>
     </tr>
    </table>
    </form>
    </body>
    </html>
    thanks for help!!
    -b

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Member
    Join Date
    Nov 2006
    Location
    Berlin
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    i will read and learn the DOM :-)

    but can you help me anyway out?

    thanks!
    -b

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're going to need to compare the contents of the text nodes.

    Text nodes have a nodeType value of 3, element nodes are type 1, and comment nodes are type 8.

    Use the data or nodeValue property of the text nodes to compare them.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •