views:

200

answers:

1

I have a form with two sets of checkboxes. The first is a list of roles on a committee (chair, vice chair, secretary, etc.) The second set of checkboxes is a list of people in those roles. For instance, Todd is our vice chair and Gwen is our treasurer. If I want to have Todd's checkbox selected when I click the vice-chair checkbox, I can do this:

$('input[name=toddS]').attr('checked', true);

But if I want to select our treasuer, I want it to not only check Gwen's checkbox, but uncheck Todd's (and all other selected checkboxes. How do I do this so that no matter what people check, it leaves only the person or people in that role checked and leaves all of the remaining checkboxes unchecked. Is that clear? Hope so.

Scott

+1  A: 

Use radio buttons instead, this way only one radio button will be checked and others un-checked automatically. No need for even jQuery. Just make sure that you name the radio buttons the same with different value, eg:

<input type="radio" name="position" value="Chairman" /> Chairman
<input type="radio" name="position" value="Vice Chairman" />Vice  Chairman
<input type="radio" name="position" value="Secretory" /> Secretory
<!-- and so on -->

Similarly, for people's:

<input type="radio" name="person" value="Todd" /> Todd
<input type="radio" name="person" value="Gwen" />Vice  Gwen
<input type="radio" name="person" value="Micheal" /> Micheal
<!-- and so on -->
Sarfraz
Some of the positions have two people in them, so I need to use checkboxes. How do I do the checkbox selection and deselection?