This should work for you...

$('#mytable input').click(function(){ 
  // get current time (class name) 
  var time = $(this).attr('class'); 
  // iterate through each input except the one clicked 
  $('#mytable input').not($(this)).each(function(){ 
    // if it has the same class name, uncheck (radio-esque functionality) 
    if ( $(this).hasClass(time) ) 
      $(this).attr('checked',''); 
  }); 
});

Demo:
http://jsbin.com/umoqe

I would add visual indications of groupings (a thin horizontal rule, e.g.)
for clarity as well.


-- SEAN O
http://www.sean-o.com
http://twitter.com/seanodotcom




newbuntu wrote:
> 
> I'm learning jquery. 
> 
> I have table like this
> 
> <table id="mytable">
>     <tr><td> <input type=checkbox
> class='08_00_AM'></td><td>Michael</td><td>21</td></tr>
>     <tr><td> <input type=checkbox
> class='08_00_AM'></td><td>Sam</td><td>22</td></tr>
>     <tr><td> <input type=checkbox
> class='08_00_AM'></td><td>John</td><td>28</td></tr>
>     <tr><td> <input type=checkbox
> class='08_00_AM'></td><td>Jason</td><td>55</td></tr>
>     <tr><td> <input type=checkbox
> class='10_00_AM'></td><td>Michael</td><td>21</td></tr>
>     <tr><td> <input type=checkbox
> class='10_00_AM'></td><td>Sam</td><td>22</td></tr>
>     <tr><td> <input type=checkbox
> class='10_00_AM'></td><td>John</td><td>28</td></tr>
>     <tr><td> <input type=checkbox
> class='10_00_AM'></td><td>Jason</td><td>55</td></tr>
> </table>
> 
> I marked input boxes with a time class (either 08_00_AM or 10_00_AM). Can
> I simulate a radio behavior for the checkboxes with the same time?
> 
> 1) if a box is checked, then all other boxes with the same time should be
> unchecked.
> 2) clicking on a checked box, should uncheck it.
> 
> any help is greatly appreciated.
> 
> thx!
> 

-- 
View this message in context: 
http://www.nabble.com/simulate-radio-with-checkboxes-in-a-table-tp22655210s27240p22659996.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to