disable entire section of checkboxes if a check box is clicked

Anjali Agarwal 1,386 Reputation points
2023-03-09T05:18:59.4133333+00:00

I want to disable a section of checkboxes if the "not interested" check box is clicked. below is my code:

<div>

I have the following JavaScript:

function Reassign(cb) {

            if (cb.checked == true) {

                document.getElementById('reassignChecks').disabled = true;

            } else {

                document.getElementById('reassignChecks').disabled = false;

            }

        }

if I click on "Not Interested" check box then I want to disable the entire section that has an ID of "reassignChecks", but with the above Javascript, this is not working. I dont want any of the checkboxes to be clicked in the reassignChecks section if Not Interested check box is clicked below is the screen shot:

User's image

any help will be appreciated.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,402 questions
0 comments No comments
{count} votes

Accepted answer
  1. QiYou-MSFT 4,311 Reputation points Microsoft Vendor
    2023-03-09T06:42:47.9566667+00:00

    Hi @Anjali Agarwal

    You can read following code:

    <script>
            function Reassign() {
                var a = document.getElementsByName("reassignChecks");
                var b = document.getElementById("cb");
                if (b.checked==true) {
                    for (var i = 0; i < a.length; i++) {
                        a[i].disabled = true;
                    }
                }
                if (b.checked == false) {
                    for (var i = 0; i < a.length; i++) {
                        a[i].disabled = false;
                    }
                }
            }
        </script>
    
     <div>
                <input type="checkbox" id="cb" onchange="Reassign()" />
                <label>Not Intersted</label>
            </div>
            <div>
                <input type="checkbox" name="reassignChecks"  />
                <label>1</label>
                <input type="checkbox" name="reassignChecks"  />
                <label>2</label>
                <input type="checkbox" name="reassignChecks"  />
                <label>3</label>
                <input type="checkbox" name="reassignChecks"  />
                <label>4</label>
            </div>
    

    Result:

    Test5

    Best regards,
    Qi You


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful