skip to Main Content

I have this function checkRule, when the value2 == "Exclusive", I call checkRule to allow select only specific Checkbox, when value2 != "Exclusive" i want to reset the checkbox behavior, to be alowed to select any of the boxes. How can I do that?

   if (value2 == "Exclusive") {
        if (RPDirect.checked == true) {
            for (var i = 0; i < Checkboxes.length; i++) {
                Checkboxes[i].addEventListener("change", checkRule);
               } 
        } 
    }
   if (value2 != "Exclusive") {
            
        }

    function checkRule(e)  {
        if (Checkboxes[7].checked == false ) {
            alert("Public must be selected.")  
        } 
        }

2

Answers


  1. A very quick Google search gave this result: https://www.w3schools.com/jsref/prop_checkbox_checked.asp

    I think that should answer your question – Checkboxes[i].checked = false;

    All the best,

    Dermot

    Login or Signup to reply.
  2. There are two approaches you could take.

    Following through with your current approach, you could use removeEventListener in the same was as you used addEventListener when value2 is changed.

    It would probably be better, however, to move any tests (such as if (value2 == "Exclusive")) which determine if a checkbox should be checked or not so they are inside checkRule.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search