tags:

views:

40

answers:

1

Hello.

I have dynamic grid-based tables in the application I am developing.

The following code works, but I need a little functionality added to it:

Current script does the following:

  1. script sees first checkbox.
  2. click first checkbox selects/deselects all checkboxes within the closest table.

New functionality wanted:

  1. script sees first checkbox.
  2. click first checkbox selects/deselects all checkboxes within the closest table.
  3. select/deselect individual checkboxes in table

here is the jquery:

<script type="text/javascript">
$(document).ready(function(){

//this code works for select ALL, but not individual checkbox select/deselect; 
$('td input:checkbox').click(function(e) {
  var table = $(e.target).closest('table');
  $('td input:checkbox', table).attr('checked', e.target.checked);
  });

});
</script>
A: 

ok i figured it out after futsing with it for waaaaay too long:

i added classes to the two different checkboxes and referenced them in the jquery.

$('td input:checkbox.selectAll').click(function(e) {
   var table = $(e.target).closest('table');
     $('td input:checkbox.selectIndividual', table).attr('checked', e.target.checked);
});
caroline