silvster27
silvster27

Reputation: 1936

How to modify a table cells value based on if a checkbox is selected AND anothers cell meets some criteria using jQuery?

I have a simple table and I want to create a flag in a td cell if the checkbox in that row is selected and the value of another cell is at least 5. I can figure out how to do the checkbox and changing the cell but I can't figure out how to use jQuery for the 'AND the other cell is at least 5' part. Here is my jsfiddle and example of what I have so far. I would also like for this to recheck anytime the user changes the value of a checkbox. http://jsfiddle.net/silvajeff/yZbQP/

$('.mySortedTable').ready(function() {
    $(".mySortedTable input.myChkBox:checked").closest('tr').find('td:eq(2)').text("Yes"); 
});

Upvotes: 0

Views: 1027

Answers (1)

Anujith
Anujith

Reputation: 9370

See this: http://jsfiddle.net/yZbQP/1/

$('.mySortedTable').ready(function() {

 $('.mySortedTable').find('tr').each(function(){

  if($(this).find('input.myChkBox').is(':checked') && parseInt($(this).find('td:eq(1)').html(),10) > 4)
    {
        $(this).find('td:eq(2)').text("Yes");
    }
 });
});

Upvotes: 1

Related Questions