Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,

i have a table, with first column name "Assign" having check box and last column name "Assigned to", i need a jQuery logic to check last column value in each row and if the value is empty make the check box checked in the first column.

What I have tried:

$("table[role='grid'] tr:not(:first)").each(function () {
var valueOfCell = $(this).find('td:last-child').text();
alert(valueOfCell);

//check if the value is empty
if (valueOfCell == ''){
// how do i get the first column ...
}
});
Posted
Updated 22-Sep-16 18:03pm

1 solution

try this

HTML
<!DOCTYPE html>
<html>
<body>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

    <table id="table1">
        <tr><td>Col1</td><td>Col2</td><td>Col3</td> </tr>
        <tr><td><input type="checkbox"></td><td>Col2</td><td>Col3</td> </tr>
        <tr><td><input type="checkbox"></td><td>Col2</td><td>Col3</td> </tr>
        <tr><td><input type="checkbox"></td><td>Col2</td><td></td> </tr>
        <tr><td><input type="checkbox"></td><td>Col2</td><td>Col3</td> </tr>
        <tr><td><input type="checkbox"></td><td>Col2</td><td>Col3</td> </tr>

    </table>     
      <script>
          $(function () {
              $("#table1 tr:not(:first)").each(function () { 
                  var valueOfCell = $(this).find('td:last-child').text();
                  var bool = valueOfCell != '';
                 var checkbox  = $(this).find(":checkbox") 
                 checkbox[0].checked = bool; 
              });
          });
      </script>

</body>
</html>


demo: - JSFiddle[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900