title: Javascript not recognizing initial checkbox value
body: <p>I'm trying to create a toggle function in Javascript for an HTML checkbox where if the checkbox is checked/unchecked, the javascript detects that with an if statement and executes an action accordingly (in this case, adding/removing a parameter to url and refreshing the page with a new set of results)</p>
  
  <p>Right now, I'm just trying to test the functionality of the javascript toggle by having alerts pop up when the box is checked/unchecked.</p>
  
  <p>Here's the javascript:</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
  function filterToggle(attribName)
  {
    var elementII = document.getElementById(attribName);
    if(elementII.checkedTag == "unchecked"){
       elementII.checkedTag = "checked";
       alert("checked");
    }
    else {
      elementII.checkedTag = "unchecked";
      alert("unchecked");
    }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>And here's where the checkboxes are being created multiple times, inside a php foreach loop:</p>
  
  <pre><code>$BODY .= sprintf("&lt;input type=\"checkbox\" onclick=\"filterToggle('%s')\" name=\"%s\" value=\"%s\" id=\"%s\" checkedTag=\"unchecked\"/&gt; %s ",
                   $attribName, $attribName, $attribClass, $attribName, $attribName, $attribName);
  </code></pre>
  
  <p>So the idea here is the boxes should load on the page unchecked (which they are), and when I check them, an alert should say "checked", and when I uncheck, and alert should say "unchecked". Everything here works perfectly, <em>except</em> the fact that when I check the boxes now, they say "unchecked", and when I uncheck, they say "checked". So it seems the javascript is changing the value of the checkedTag attribute in the checkboxes and responding accordingly, <em>but</em> it's not recognizing the fact that the value of the checkbox is initially set to "unchecked", so that instead of setting it to unchecked and alerting "unchecked" when first clicked, as it's currently seemingly doing, it should set it to "checked" and alert "checked".</p>
  
  <p>Any thoughts here? I can't figure out why it's not recognizing that initial value - tried double quotations around the checkedTag value, single quotations, no quotations...same result.</p>
  
  <p>Here's some example output code in JSFiddle - <a href="http://jsfiddle.net/intenex/s45JC/3/" rel="nofollow">http://jsfiddle.net/intenex/s45JC/3/</a>, with 3 checkboxes displaying the error described above.</p>
  
  <p>Thanks!</p>