title: How to show Javascript confirm box when checkbox is unchecked and then if user selects cancel, leave the checkbox checked?
body: <p>I have a small <code>html form</code> with three checkboxes, one in each <code>row</code>. I want to have a <code>javascript confirm box</code> show when the user unchecks the box, and then if the user selects cancel, the <code>checkbox</code> remains checked. I've searched this site and a few others but almost everything was to do with the <code>checkbox</code> being checked, like if they had to agree to some terms or something. I am very new to <code>Javascript</code> however I tried to make a function based on what I though it should look like, but it doesn't work.</p>
  
  <p>Here is my form:</p>
  
  <pre><code>&lt;form action="" method="post"&gt;
    &lt;table id="table"&gt;
      &lt;tr&gt;
        &lt;td&gt;Checkbox One&lt;/td&gt;
        &lt;td align="center"&gt;
          &lt;input type="checkbox" name="check1" checked="checked" onchange="cTrig(this.name)"&gt;&lt;/input&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;Checkbox Two&lt;/td&gt;
        &lt;td align="center"&gt;
          &lt;input type="checkbox" name="check2" checked="checked" onchange="cTrig(this.name)"&gt;&lt;/input&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;Checkbox Three&lt;/td&gt;
        &lt;td align="center"&gt;
          &lt;input type="checkbox" name="check3" checked="checked" onchange="cTrig(this.name)"&gt;&lt;/input&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr align="center"&gt;
        &lt;td colspan="2"&gt;
          &lt;input type="submit" name="submit" value="submit"&gt;&lt;/input&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And here is the function I tried, but doesn't work:</p>
  
  <pre><code>function cTrig(name) {
    if (name.checked == true) {
      confirm("Are you sure you want to do this?");
      return true;
    } else {
      return false;
    }
  }
  </code></pre>
  
  <p>Here is a <a href="http://jsfiddle.net/RbENV/1/" rel="noreferrer">jsfiddle</a></p>
  
  <p>I would prefer something in <code>Javascript</code> as I want to become more familiar with that language before getting into <code>jquery</code>, but if it has to be done in <code>jquery</code>, then that is fine. Cheers.</p>