uncheck box after checking a box

Scot King 116 Reputation points
2021-12-12T22:37:12.613+00:00

I have a couple of checkboxes in a popup. When I check on one of them, if you attempt to check on another one, it will uncheck the one you just checked. There are just two boxes. I tried the following and this line: cbbizperc.checked = false; doesn't seem to work. Can someone possibly offer a suggestion?

<script type="text/javascript">
function cborbizpercent() {
var cbselfemp = document.getElementById('<%=cbcborselfemp.ClientID%>');
var cbbizperc = document.getElementById('<%=cbcboremprelatedparty.ClientID%>');
if (cbselfemp.checked == true) {
var rb = document.getElementById("<%= rblcborownership25.ClientID %>");
var radio = rb.getElementsByTagName("input");
var label = rb.getElementsByTagName("label");
for (var i = 0; i < radio.length; i++) {
(radio[i].disabled) = false;
}
if (cbbizperc.checked == true) {
cbbizperc.checked = false;
//document.getElementById('<%=cbcboremprelatedparty.ClientID%>').checked = false;
}
} else {
var rb = document.getElementById("<%= rblcborownership25.ClientID %>");
var radio = rb.getElementsByTagName("input");
var label = rb.getElementsByTagName("label");
for (var i = 0; i < radio.length; i++) {
(radio[i].disabled) = true;
(radio[i]).checked = false;
}
}
}
</script>

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
827 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Scot King 116 Reputation points
    2021-12-13T15:21:20.777+00:00

    I guess I put a visual basic tag on this. It should really be a javascript tag.

    Do not be confused about the radio button. they are there also. But it's the checkbox I'm trying to check and uncheck.
    if (cbbizperc.checked == true) {
    cbbizperc.checked = false;
    //document.getElementById('<%=cbcboremprelatedparty.ClientID%>').checked = false;


  2. Jose Zero 571 Reputation points
    2021-12-13T21:05:40.007+00:00

    There is nothing wrong with your Javascript, if I make a page with 2 CheckBox and use you function it is fine.
    Are you sure there is no postback?

    0 comments No comments