Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Consider using the the 'checked' parameter of you checkOnly function to determine which checkbox the user checked (maybe give them unique ids). As your logic stands now, if you check the first checkbox, it will clear out the checkboxes on the last four. Then if you check the last checkbox, it will still clear out the last four checkboxes <strong><em>because the first checkbox is still checked</em></strong>. This makes it look like the last four checkboxes are disabled even though they aren't.</p> <p>For example:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;FooBar&lt;/title&gt; &lt;script language="javascript"&gt; function checkOnly(myCheckbox) { var checkboxChanged = false; var checkedTotalValue = 0; var changedTotalValue = 0; for(var i = 0; i &lt; document.myForm.elements.length; i++) { if(document.myForm.elements[i].name != myCheckbox.name) { if(document.myForm.elements[i].checked == true) { checkboxChanged = true; changedTotalValue += parseInt(document.myForm.elements[i].value); } document.myForm.elements[i].checked = false; } if(document.myForm.elements[i].checked == true) { checkedTotalValue += parseInt(document.myForm.elements[i].value); } } if(checkboxChanged) { alert('Checked: ' + checkedTotalValue + ', Changed: ' + changedTotalValue); } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form name="myForm"&gt; &lt;input type="checkbox" name="checkboxGroup1" id="cb" value="1" onClick="checkOnly(this)"&gt; &lt;input type="checkbox" name="checkboxGroup1" id="cb" value="1" onClick="checkOnly(this)"&gt; &lt;input type="checkbox" name="checkboxGroup1" id="cb" value="1" onClick="checkOnly(this)"&gt; &lt;input type="checkbox" name="checkboxGroup1" id="cb" value="1" onClick="checkOnly(this)"&gt; &lt;input type="checkbox" name="checkboxGroup2" id="cb" value="1" onClick="checkOnly(this)"&gt; &lt;input type="checkbox" name="checkboxGroup2" id="cb" value="1" onClick="checkOnly(this)"&gt; &lt;input type="checkbox" name="checkboxGroup2" id="cb" value="1" onClick="checkOnly(this)"&gt; &lt;input type="checkbox" name="checkboxGroup2" id="cb" value="1" onClick="checkOnly(this)"&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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