Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 2.50 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
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
Old 02-13-2009, 12:54 AM   PM User | #2
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
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
harbingerOTV is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:39 AM.


Advertisement
Log in to turn off these ads.