Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy javascript not working on checkbox?
    text
    copied!<p>I have two groups of checboxes, when i click on first group of checkboxes the second group of checkbox should be unchecked. but the second checkbox unchecked when I click on first checkbox two times. here is my javascript code</p> <pre><code> &lt;script&gt; function uncheck0(){ for(var ii=1; ii&lt;=3; ii++){ if(document.getElementById("q6_"+ii).checked==true){ document.getElementById("q6_"+ii).checked=false; } } } function uncheck(id, from, to){ for(var ii=from; ii&lt;=to; ii++){ if(document.getElementById(id+ii).checked==true){ document.getElementById(id+ii).checked=false; } } } &lt;/script&gt; </code></pre> <p>and here is my <strong>html code</strong> first group has <strong>radio-buttons</strong> and second has checkboxes</p> <pre><code>&lt;p&gt;IF YES: When will the review begin?&lt;/p&gt; &lt;label for="q6"&gt;&lt;input type="radio" class="styled" value="Within the next 12 months" name="q6[]" id="q6_1"&gt;Within the next 12 months&lt;/label&gt; &lt;label for="q6"&gt;&lt;input type="radio" class="styled" value="Within the next 24 months" name="q6[]" id="q6_2"&gt;Within the next 24 months&lt;/label&gt; &lt;label for="q6"&gt;&lt;input type="radio" class="styled" value="We are currently doing it" name="q6[]" id="q6_3"&gt;We are currently doing it&lt;/label&gt;&lt;br&gt; &lt;br&gt; &lt;p&gt;IF NO: Why Not&lt;/p&gt; &lt;label onclick="uncheck('q6_',1,3);" for="q6"&gt;&lt;input type="checkbox" class="styled" value="Lack of budget" name="q6[]" id="q6_4"&gt;Lack of budget&lt;/label&gt; &lt;label onclick="uncheck('q6_',1,3);" for="q6"&gt;&lt;input type="checkbox" class="styled" value="Lack of resource" name="q6[]" id="q6_5"&gt;Lack of resource&lt;/label&gt; &lt;label onclick="uncheck('q6_',1,3);" for="q6"&gt;&lt;input type="checkbox" class="styled" value="Do not see the need" name="q6[]" id="q6_6"&gt;Do not see the need&lt;/label&gt; &lt;label onclick="uncheck('q6_',1,3);" for="q6"&gt;&lt;input type="checkbox" class="styled" value="Lack of know how/expertise" name="q6[]" id="q6_7"&gt;Lack of know how/expertise&lt;/label&gt; &lt;label onclick="uncheck('q6_',1,3);" for="q6"&gt;&lt;input type="checkbox" class="styled" value="Complexity" name="q6[]" id="q6_8"&gt;Complexity&lt;/label&gt; &lt;label onclick="uncheck('q6_',1,3);" for="q6"&gt;&lt;input type="checkbox" class="styled" value="Contractual obligations" name="q6[]" id="q6_9"&gt;Contractual obligations&lt;/label&gt; &lt;label onclick="uncheck('q6_',1,3);" for="q5"&gt;&lt;input type="checkbox" class="styled" value="Other" name="q6[]" id="q6_10"&gt;Other &lt;/label&gt; &lt;label onclick="uncheck('q6_',1,3);" for="q5a"&gt;Please state&lt;/label&gt;&lt;input type="text" value="" id="q6a" name="q6a"&gt; </code></pre> <p>I have use a javascript file "custom-form-element.js" for checkbox and radio styling</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload