jeudi 2 novembre 2017

Uncheck a checkbox when another is checked

< script >

  function uncheck() {
    var notTest = document.getElementById("choice_31_3_2");
    var Test = document.getElementById("choice_31_3_1");

    if (notTest.checked) {
      Test.checked = false;
    }
    if (Test.checked) {
      notTest.checked = false;
    }
  }

jQuery("#choice_31_3_1").click(uncheck);
jQuery("#choice_31_3_2").click(uncheck);

< /script >
<script src="http://ift.tt/1oMJErh"></script>


<input name="input_3.1" value="Test" id="choice_31_3_1" type="checkbox">
<label for="choice_31_3_1" id="label_31_3_1">Test</label>
<input name="input_3.2" value="notTest" id="choice_31_3_2" type="checkbox">
<label for="choice_31_3_2" id="label_31_3_2">notTest</label>

I wrote a function to uncheck a checkbox if another one is checked, i am using jQuery to call uncheck() on those specific input.

I am getting the result i want. when i check test then check notTest, Test is being unchecked. BUT when i am pressing Test again, the test checkbox is refusing to chech unless i manually uncheck notTest.

I included the code snippet , please can figure out what is wrong ?

The code is running normally on Wordpress but unfortunately not here.




Aucun commentaire:

Enregistrer un commentaire