Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What may be happening is that your <code>CheckBoxID</code> is wrong, and therefore returning the wrong element. </p> <p>In JavaScript, saying <code>checkbox.checked = false;</code> will, if this object did not previously have a <code>checked</code> property, <strong>add one</strong> to the object, with the value provided. So, if your <code>CheckBoxID</code> is in fact wrong, it's no surprise your alert shows false; any non-null element you pull back with <code>getElementById</code> will allow you to add a checked property to it.</p> <p>More specifically, in <code>asp.net</code> when you create a checkbox column, like this</p> <pre><code>&lt;asp:CheckBoxField Text="Hello" DataField="foo" /&gt; </code></pre> <p>it renders html like this:</p> <pre><code>&lt;span class="aspNetDisabled"&gt; &lt;input id="gv_ctl00_0" type="checkbox" name="gv$ctl02$ctl00" disabled="disabled"&gt; &lt;label for="gv_ctl00_0"&gt;Hello&lt;/label&gt; &lt;/span&gt; </code></pre> <p>A couple possibilities: </p> <ol> <li>The id you're getting may be of the span, on which you're adding a checked property.</li> <li><strike>You're setting the checkbox to be checked, but since it's disabled, it's not updating its state</strike> -- ok, it looks like disabled checkboxes can have their checked properties updated. Hopefully #1 is your problem. </li> </ol> <p>A good place to start debugging would be to change your function to this</p> <pre><code>function UncheckedItemsCheckBox(CheckboxID) { var checkbox = document.getElementById(CheckboxID); alert(checkbox.checked); // &lt;------- should display false, but will // display undefined if this element is // something other than a checkbox checkbox.checked = false; alert(checkbox.id + " : " + checkbox.name + " : " + checkbox.checked); } </code></pre>
 

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