views:

443

answers:

2

I know my question reads a bit like that 'how much wood can a woodchuck chuck' line, please excuse that...

I have a repeater with checkboxes. There are numerous rows in this repeater - I never know how many - I want only one checkbox checked at any time. If the user changes the checked checkbox, any pre-existing checks are unchecked therefore maintaining a single checked checkbox.

I am using VB, but comfortable to port any C#. I want to use JQuery. I have been looking on Google, but only ever seem to find ALL checked, ALL unchecked systems.

Any suggestions?

+4  A: 
$('input:checkbox').change(function() {
    $('input:checkbox').not(this).removeAttr('checked');
});
reko_t
Thank you Reko. I gave the answer to kpower because of his extra explanation, but I up-voted your answer also. Many thanks.
Chris Laythorpe
+5  A: 

First of all, add some class to all checkboxes of group-with-one-checked to determine it. For example, class="radio-similar".

Then:

$('.radio-similar').change(function () {
  if ($(this).is(':checked')) {
    $('.radio-similar').not(this).removeAttr('checked');
  };
});
kpower
Spot on. Thank you :)
Chris Laythorpe