I have a CheckBoxList dinamically filled from DB.
<asp:CheckBoxList ID="chklist1" runat="server" onclick="chklist1_onclick()" />
Oce it has been filled I have several options and one of them has the text "No Response".
What I want is a javascript function that does the following:
1) If I check "No Response" all other options must be unchecked.
2) If I check at least one of the options that is not "No Response", the "No Response" option must be unchecked.
Hope to be clear. Thanks in advance.
My attempt was:
function chklist1_onclick() {
var chklist1 = document.getElementById('<%= chklist1.ClientID %>');
var chkList = chklist1.getElementsByTagName("input");
for (var i = 0; i < chkList.length; i++) {
if (chkList[i].checked && chkList[i].value == "6") {
for (var i = 0; i < chkList.length; i++) {
if (chkList[i].checked && chkList[i].value != "6") {
chkList[i].checked = false;
}
}
}
}
}
Where 6 is the value of "No Response" item. But this way I only resolve the case 1)
Slightly modified version of Darin's solution, I think this one is IE8 compatible.
I solved with the following code:
and removed the onclick event in the asp tag.
Assuming that the
No Response
checkbox hasvalue=""
you could try the following script:If your No Response checkbox has a different value than the empty string simply adapt the tests in the previous example.