Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,788
    Thanks
    8
    Thanked 131 Times in 129 Posts

    [jQuery] finding all matching table cell values

    I am using this in my code to find all the second cells in a table and grab the html of those cells:
    PHP Code:
    var secondCell = $(this).find('td').eq(1).html(); 
    I have a set of radio buttons in each row that when clicked, add a class to the row then add a button to that row like so:
    PHP Code:
     $('tr input.blacklist').click(function() {
         $(
    this).parent().parent().find(".confirm").empty();     
            if ( 
    this.checked )
                 $(
    this).parent().parent().find(".confirm").html("<a href='#x' class='blacklist'><img src='blacklist.jpg' border='0' \/><\/a>"),
                 $(
    this).parent().parent().addClass('blacklist');

            else
                 $(
    this).parent().parent().find(".confirm").empty(),
                 $(
    this).parent().parent().removeClass('blacklist');
     }); 
    then when that generated button is clicked it removes the row from the table like this:

    PHP Code:
    $('a.blacklist')
        .
    livequery('click', function(event) {
            $(
    this).parent().parent().remove();

    //... some other fluff that doesn't relate to this at all 

    Basically I have two radios. One for 'delete' and one for 'blacklist'. When you check the radio for 'blacklist' I want it to compare the contents of all the remaining second table cells left in the table. Then for each identical match in the HTML of the second TD of each row, apply the class 'delete' to that row. Now when the button 'blacklist' is checked, it removes all corresponding rows.

    I think that is written well enough.

    [edit]

    here's something I just tried and it kinda works. It checks all the second cells and if there is one that matches another it produces an alert of "match" else it produces "no match"

    PHP Code:
     $('tr input.blacklist').click(function() {
         $(
    this).parent().parent().find(".confirm").empty();
          var 
    indenticalIP = $(this).parent().parent().find('td').eq(1).html();
          if ( 
    this.checked )
                 $(
    "#rr").append(indenticalIP),
                 $(
    this).parent().parent().find(".confirm").html("<a href='#x' class='blacklist'><img src='blacklist.jpg' border='0' \/><\/a>"),
                 $(
    this).parent().parent().addClass('blacklist');

          else
                 $(
    this).parent().parent().find(".confirm").empty(),
                 $(
    this).parent().parent().removeClass('blacklist');
                 
    if ($(
    this).parent().parent().parent().find('td').eq(1).html() == indenticalIP)
    alert("match");
    else
    alert("no match");

     }); 
    [Edit]

    The above produces a false positive as it only checks the first row. grrr.
    Last edited by harbingerOTV; 02-10-2009 at 01:19 PM.
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

  • #2
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,788
    Thanks
    8
    Thanked 131 Times in 129 Posts
    using this:

    PHP Code:
    $('tr input.blacklist').click(function() {
       var 
    indenticalIP = $(this).parent().parent().find('td').eq(1).html();
          $(
    'tr').each(function(){
             if($(
    this).children('td').eq(1).html() == indenticalIP)
                $(
    this).css('background','#96d');
          });
    }); 
    in a table like this:

    Code:
    <table>
    <tr><td>stuff</td><td>1.1.1.1.1</td><td><input type="radio" class="blacklist" name="a1"></td></tr>
    <tr><td>stuff</td><td>0.1.0.1.0</td><td><input type="radio" class="blacklist" name="a2"></td></tr>
    <tr><td>stuff</td><td>1.1.1.1.1</td><td><input type="radio" class="blacklist" name="a3"></td></tr>
    </table>
    upon selecting the radio, grab the content of the second field. Then loop through all rows and all cells in that row. If any of the cells have the same content of the one clicked, it will then turn the row purple.

    have fun.
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis


  •  

    Posting Permissions

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