Reputation: 951
On my survey page I have a group of radiobuttonlists with identical items all have the same class:
<asp:RadioButtonList ID = "rbFirstList" runat = "server" CssClass= "tbiDiagnosis">
<asp:ListItem Text = "0. No" Value = "0"></asp:ListItem>
<asp:ListItem Text = "1. Yes, one episode" Value = "1"></asp:ListItem>
<asp:ListItem Text = "2. Yes, two episodes" Value = "2"></asp:ListItem>
<asp:ListItem Text = "3. Yes, three episodes" Value = "3"></asp:ListItem>
<asp:ListItem Text = "4. Yes, four episodes" Value = "4"></asp:ListItem>
<asp:ListItem Text = "5. Yes, five or more episodes" Value = "5"></asp:ListItem>
<asp:ListItem Text = "6. Uncertain" Value = "6"></asp:ListItem>
</asp:RadioButtonList>
<asp:RadioButtonList ID = "rbSecondList" runat = "server" CssClass= "tbiDiagnosis">
<asp:ListItem Text = "0. No" Value = "0"></asp:ListItem>
<asp:ListItem Text = "1. Yes, one episode" Value = "1"></asp:ListItem>
<asp:ListItem Text = "2. Yes, two episodes" Value = "2"></asp:ListItem>
<asp:ListItem Text = "3. Yes, three episodes" Value = "3"></asp:ListItem>
<asp:ListItem Text = "4. Yes, four episodes" Value = "4"></asp:ListItem>
<asp:ListItem Text = "5. Yes, five or more episodes" Value = "5"></asp:ListItem>
<asp:ListItem Text = "6. Uncertain" Value = "6"></asp:ListItem>
</asp:RadioButtonList>
I am trying to prevent all radiobuttonlists have "no" selected(value 0), so when I select(click) one of them I need to know what values they all have selected except the one that I clicked.
$('.tbiDiagnosis input:radio').click(function(e) {
if ($(this).val() == 0) {
//selector is obviously incorrect, how would I do it here?
if ('.tbiDiagnosis input:checked:not($this)).val() > 0).length == 0)
e.preventDefault();
}
});
Thanks.
Upvotes: 0
Views: 176
Reputation: 12806
It's a bit unclear what your after, perhaps you could explain in more detail what you're after. I think what you're looking for can be achieved by filtering by value attribute [value='0']
see example below (untested). I hope this helps.
$('.tbiDiagnosis input:radio').click(function(e) {
if ($(this).val() == 0) {
var checked = $(".tbiDiagnosis input:checked");
var filtered = checked.not(checked.find("[value='0']"));
if (filtered.length == 0)
e.preventDefault();
}
});
Upvotes: 1