View Single Post
Old 02-09-2009, 11:44 PM   PM User | #1
harbingerOTV
Senior Coder

 
Join Date: Jan 2005
Location: Memphis, TN
Posts: 1,765
Thanks: 8
Thanked 123 Times in 121 Posts
harbingerOTV will become famous soon enough
[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.
__________________
Stop making things so hard on yourself.
i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

Last edited by harbingerOTV; 02-10-2009 at 01:19 PM..
harbingerOTV is offline   Reply With Quote